| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [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_64.h" |
| 18 | |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 19 | #include "art_method.h" |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 20 | #include "class_table.h" |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 21 | #include "code_generator_utils.h" |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 25 | #include "gc/space/image_space.h" |
| Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 26 | #include "heap_poisoning.h" |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 27 | #include "intrinsics.h" |
| 28 | #include "intrinsics_x86_64.h" |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 29 | #include "linker/linker_patch.h" |
| Andreas Gampe | d490129 | 2017-05-30 18:41:34 -0700 | [diff] [blame] | 30 | #include "lock_word.h" |
| Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 31 | #include "mirror/array-inl.h" |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 32 | #include "mirror/class-inl.h" |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 33 | #include "mirror/object_reference.h" |
| 34 | #include "thread.h" |
| 35 | #include "utils/assembler.h" |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 36 | #include "utils/stack_checks.h" |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 37 | #include "utils/x86_64/assembler_x86_64.h" |
| 38 | #include "utils/x86_64/managed_register_x86_64.h" |
| 39 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 40 | namespace art { |
| 41 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 42 | template<class MirrorType> |
| 43 | class GcRoot; |
| 44 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 45 | namespace x86_64 { |
| 46 | |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 47 | static constexpr int kCurrentMethodStackOffset = 0; |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 48 | static constexpr Register kMethodRegisterArgument = RDI; |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 49 | // The compare/jump sequence will generate about (1.5 * num_entries) instructions. A jump |
| 50 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 51 | // generates less code/data with a small num_entries. |
| 52 | static constexpr uint32_t kPackedSwitchJumpTableThreshold = 5; |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 53 | |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 54 | static constexpr Register kCoreCalleeSaves[] = { RBX, RBP, R12, R13, R14, R15 }; |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 55 | static constexpr FloatRegister kFpuCalleeSaves[] = { XMM12, XMM13, XMM14, XMM15 }; |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 56 | |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 57 | static constexpr int kC2ConditionMask = 0x400; |
| 58 | |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 59 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 60 | // Custom calling convention: RAX serves as both input and output. |
| 61 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 62 | caller_saves.Add(Location::RegisterLocation(RAX)); |
| 63 | return caller_saves; |
| 64 | } |
| 65 | |
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 66 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 67 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> // NOLINT |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 68 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86_64PointerSize, x).Int32Value() |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 69 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 70 | class NullCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 71 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 72 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : SlowPathCode(instruction) {} |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 73 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 74 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 75 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 76 | __ Bind(GetEntryLabel()); |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 77 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 78 | // Live registers will be restored in the catch block if caught. |
| 79 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 80 | } |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 81 | x86_64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 82 | instruction_, |
| 83 | instruction_->GetDexPc(), |
| 84 | this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 85 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 86 | } |
| 87 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 88 | bool IsFatal() const override { return true; } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 89 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 90 | const char* GetDescription() const override { return "NullCheckSlowPathX86_64"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 91 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 92 | private: |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 93 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 94 | }; |
| 95 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 96 | class DivZeroCheckSlowPathX86_64 : public SlowPathCode { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 97 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 98 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 99 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 100 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 101 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 102 | __ Bind(GetEntryLabel()); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 103 | x86_64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 104 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 107 | bool IsFatal() const override { return true; } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 108 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 109 | const char* GetDescription() const override { return "DivZeroCheckSlowPathX86_64"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 110 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 111 | private: |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 112 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 113 | }; |
| 114 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 115 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCode { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 116 | public: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 117 | DivRemMinusOneSlowPathX86_64(HInstruction* at, Register reg, DataType::Type type, bool is_div) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 118 | : SlowPathCode(at), cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 119 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 120 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 121 | __ Bind(GetEntryLabel()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 122 | if (type_ == DataType::Type::kInt32) { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 123 | if (is_div_) { |
| 124 | __ negl(cpu_reg_); |
| 125 | } else { |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 126 | __ xorl(cpu_reg_, cpu_reg_); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 129 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 130 | DCHECK_EQ(DataType::Type::kInt64, type_); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 131 | if (is_div_) { |
| 132 | __ negq(cpu_reg_); |
| 133 | } else { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 134 | __ xorl(cpu_reg_, cpu_reg_); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 135 | } |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 136 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 137 | __ jmp(GetExitLabel()); |
| 138 | } |
| 139 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 140 | const char* GetDescription() const override { return "DivRemMinusOneSlowPathX86_64"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 141 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 142 | private: |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 143 | const CpuRegister cpu_reg_; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 144 | const DataType::Type type_; |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 145 | const bool is_div_; |
| 146 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 147 | }; |
| 148 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 149 | class SuspendCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 150 | public: |
| Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 151 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 152 | : SlowPathCode(instruction), successor_(successor) {} |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 153 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 154 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 155 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 156 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 157 | __ Bind(GetEntryLabel()); |
| Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 158 | SaveLiveRegisters(codegen, locations); // Only saves full width XMM for SIMD. |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 159 | x86_64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 160 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
| Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 161 | RestoreLiveRegisters(codegen, locations); // Only restores full width XMM for SIMD. |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 162 | if (successor_ == nullptr) { |
| 163 | __ jmp(GetReturnLabel()); |
| 164 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 165 | __ jmp(x86_64_codegen->GetLabelOf(successor_)); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 166 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 169 | Label* GetReturnLabel() { |
| 170 | DCHECK(successor_ == nullptr); |
| 171 | return &return_label_; |
| 172 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 173 | |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 174 | HBasicBlock* GetSuccessor() const { |
| 175 | return successor_; |
| 176 | } |
| 177 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 178 | const char* GetDescription() const override { return "SuspendCheckSlowPathX86_64"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 179 | |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 180 | private: |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 181 | HBasicBlock* const successor_; |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 182 | Label return_label_; |
| 183 | |
| 184 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 185 | }; |
| 186 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 187 | class BoundsCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 188 | public: |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 189 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 190 | : SlowPathCode(instruction) {} |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 191 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 192 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 193 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 194 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 195 | __ Bind(GetEntryLabel()); |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 196 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 197 | // Live registers will be restored in the catch block if caught. |
| 198 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 199 | } |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 200 | // Are we using an array length from memory? |
| 201 | HInstruction* array_length = instruction_->InputAt(1); |
| 202 | Location length_loc = locations->InAt(1); |
| 203 | InvokeRuntimeCallingConvention calling_convention; |
| 204 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 205 | // Load the array length into our temporary. |
| Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 206 | HArrayLength* length = array_length->AsArrayLength(); |
| Nicolas Geoffray | 003444a | 2017-10-17 10:58:42 +0100 | [diff] [blame] | 207 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(length); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 208 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 209 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
| 210 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 211 | // Check for conflicts with index. |
| 212 | if (length_loc.Equals(locations->InAt(0))) { |
| 213 | // We know we aren't using parameter 2. |
| 214 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 215 | } |
| 216 | __ movl(length_loc.AsRegister<CpuRegister>(), array_len); |
| Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 217 | if (mirror::kUseStringCompression && length->IsStringLength()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 218 | __ shrl(length_loc.AsRegister<CpuRegister>(), Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 219 | } |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 220 | } |
| 221 | |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 222 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 223 | // move resolver. |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 224 | codegen->EmitParallelMoves( |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 225 | locations->InAt(0), |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 226 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 227 | DataType::Type::kInt32, |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 228 | length_loc, |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 229 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 230 | DataType::Type::kInt32); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 231 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 232 | ? kQuickThrowStringBounds |
| 233 | : kQuickThrowArrayBounds; |
| 234 | x86_64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 235 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 236 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 237 | } |
| 238 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 239 | bool IsFatal() const override { return true; } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 240 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 241 | const char* GetDescription() const override { return "BoundsCheckSlowPathX86_64"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 242 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 243 | private: |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 244 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 245 | }; |
| 246 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 247 | class LoadClassSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 248 | public: |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 249 | LoadClassSlowPathX86_64(HLoadClass* cls, HInstruction* at) |
| 250 | : SlowPathCode(at), cls_(cls) { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 251 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 252 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 253 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 254 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 255 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 256 | LocationSummary* locations = instruction_->GetLocations(); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 257 | Location out = locations->Out(); |
| 258 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 259 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 260 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
| 261 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 262 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 263 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 264 | SaveLiveRegisters(codegen, locations); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 265 | |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 266 | // Custom calling convention: RAX serves as both input and output. |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 267 | if (must_resolve_type) { |
| 268 | DCHECK(IsSameDexFile(cls_->GetDexFile(), x86_64_codegen->GetGraph()->GetDexFile())); |
| 269 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 270 | __ movl(CpuRegister(RAX), Immediate(type_index.index_)); |
| Vladimir Marko | 9d47925 | 2018-07-24 11:35:20 +0100 | [diff] [blame] | 271 | x86_64_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 272 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 273 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 274 | } else { |
| 275 | DCHECK(must_do_clinit); |
| 276 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 277 | x86_64_codegen->Move(Location::RegisterLocation(RAX), source); |
| 278 | } |
| 279 | if (must_do_clinit) { |
| 280 | x86_64_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 281 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 282 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 283 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 284 | // Move the class to the desired location. |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 285 | if (out.IsValid()) { |
| 286 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 287 | x86_64_codegen->Move(out, Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 288 | } |
| 289 | |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 290 | RestoreLiveRegisters(codegen, locations); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 291 | __ jmp(GetExitLabel()); |
| 292 | } |
| 293 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 294 | const char* GetDescription() const override { return "LoadClassSlowPathX86_64"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 295 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 296 | private: |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 297 | // The class this slow path will load. |
| 298 | HLoadClass* const cls_; |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 299 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 300 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 301 | }; |
| 302 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 303 | class LoadStringSlowPathX86_64 : public SlowPathCode { |
| 304 | public: |
| 305 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : SlowPathCode(instruction) {} |
| 306 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 307 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 308 | LocationSummary* locations = instruction_->GetLocations(); |
| 309 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 310 | |
| 311 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 312 | __ Bind(GetEntryLabel()); |
| 313 | SaveLiveRegisters(codegen, locations); |
| 314 | |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 315 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 316 | // Custom calling convention: RAX serves as both input and output. |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 317 | __ movl(CpuRegister(RAX), Immediate(string_index.index_)); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 318 | x86_64_codegen->InvokeRuntime(kQuickResolveString, |
| 319 | instruction_, |
| 320 | instruction_->GetDexPc(), |
| 321 | this); |
| 322 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 323 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| 324 | RestoreLiveRegisters(codegen, locations); |
| 325 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 326 | __ jmp(GetExitLabel()); |
| 327 | } |
| 328 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 329 | const char* GetDescription() const override { return "LoadStringSlowPathX86_64"; } |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 330 | |
| 331 | private: |
| 332 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 333 | }; |
| 334 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 335 | class TypeCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 336 | public: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 337 | TypeCheckSlowPathX86_64(HInstruction* instruction, bool is_fatal) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 338 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 339 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 340 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 341 | LocationSummary* locations = instruction_->GetLocations(); |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 342 | uint32_t dex_pc = instruction_->GetDexPc(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 343 | DCHECK(instruction_->IsCheckCast() |
| 344 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 345 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 346 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 347 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 348 | |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 349 | if (kPoisonHeapReferences && |
| 350 | instruction_->IsCheckCast() && |
| 351 | instruction_->AsCheckCast()->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) { |
| 352 | // First, unpoison the `cls` reference that was poisoned for direct memory comparison. |
| 353 | __ UnpoisonHeapReference(locations->InAt(1).AsRegister<CpuRegister>()); |
| 354 | } |
| 355 | |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 356 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 357 | SaveLiveRegisters(codegen, locations); |
| 358 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 359 | |
| 360 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 361 | // move resolver. |
| 362 | InvokeRuntimeCallingConvention calling_convention; |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 363 | codegen->EmitParallelMoves(locations->InAt(0), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 364 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 365 | DataType::Type::kReference, |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 366 | locations->InAt(1), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 367 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 368 | DataType::Type::kReference); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 369 | if (instruction_->IsInstanceOf()) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 370 | x86_64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 371 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 372 | } else { |
| 373 | DCHECK(instruction_->IsCheckCast()); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 374 | x86_64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 375 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 376 | } |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 377 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 378 | if (!is_fatal_) { |
| 379 | if (instruction_->IsInstanceOf()) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 380 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 381 | } |
| Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 382 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 383 | RestoreLiveRegisters(codegen, locations); |
| 384 | __ jmp(GetExitLabel()); |
| 385 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 388 | const char* GetDescription() const override { return "TypeCheckSlowPathX86_64"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 389 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 390 | bool IsFatal() const override { return is_fatal_; } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 391 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 392 | private: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 393 | const bool is_fatal_; |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 394 | |
| 395 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 396 | }; |
| 397 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 398 | class DeoptimizationSlowPathX86_64 : public SlowPathCode { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 399 | public: |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 400 | explicit DeoptimizationSlowPathX86_64(HDeoptimize* instruction) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 401 | : SlowPathCode(instruction) {} |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 402 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 403 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 404 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 405 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 406 | LocationSummary* locations = instruction_->GetLocations(); |
| 407 | SaveLiveRegisters(codegen, locations); |
| 408 | InvokeRuntimeCallingConvention calling_convention; |
| 409 | x86_64_codegen->Load32BitValue( |
| 410 | CpuRegister(calling_convention.GetRegisterAt(0)), |
| 411 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 412 | x86_64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 413 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 414 | } |
| 415 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 416 | const char* GetDescription() const override { return "DeoptimizationSlowPathX86_64"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 417 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 418 | private: |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 419 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 420 | }; |
| 421 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 422 | class ArraySetSlowPathX86_64 : public SlowPathCode { |
| 423 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 424 | explicit ArraySetSlowPathX86_64(HInstruction* instruction) : SlowPathCode(instruction) {} |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 425 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 426 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 427 | LocationSummary* locations = instruction_->GetLocations(); |
| 428 | __ Bind(GetEntryLabel()); |
| 429 | SaveLiveRegisters(codegen, locations); |
| 430 | |
| 431 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 432 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 433 | parallel_move.AddMove( |
| 434 | locations->InAt(0), |
| 435 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 436 | DataType::Type::kReference, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 437 | nullptr); |
| 438 | parallel_move.AddMove( |
| 439 | locations->InAt(1), |
| 440 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 441 | DataType::Type::kInt32, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 442 | nullptr); |
| 443 | parallel_move.AddMove( |
| 444 | locations->InAt(2), |
| 445 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 446 | DataType::Type::kReference, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 447 | nullptr); |
| 448 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 449 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 450 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 451 | x86_64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 452 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 453 | RestoreLiveRegisters(codegen, locations); |
| 454 | __ jmp(GetExitLabel()); |
| 455 | } |
| 456 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 457 | const char* GetDescription() const override { return "ArraySetSlowPathX86_64"; } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 458 | |
| 459 | private: |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 460 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86_64); |
| 461 | }; |
| 462 | |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 463 | // Slow path marking an object reference `ref` during a read |
| 464 | // barrier. The field `obj.field` in the object `obj` holding this |
| 465 | // reference does not get updated by this slow path after marking (see |
| 466 | // ReadBarrierMarkAndUpdateFieldSlowPathX86_64 below for that). |
| 467 | // |
| 468 | // This means that after the execution of this slow path, `ref` will |
| 469 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 470 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 471 | // probably still be a from-space reference (unless it gets updated by |
| 472 | // another thread, or if another thread installed another object |
| 473 | // reference (different from `ref`) in `obj.field`). |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 474 | class ReadBarrierMarkSlowPathX86_64 : public SlowPathCode { |
| 475 | public: |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 476 | ReadBarrierMarkSlowPathX86_64(HInstruction* instruction, |
| 477 | Location ref, |
| 478 | bool unpoison_ref_before_marking) |
| 479 | : SlowPathCode(instruction), |
| 480 | ref_(ref), |
| 481 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 482 | DCHECK(kEmitCompilerReadBarrier); |
| 483 | } |
| 484 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 485 | const char* GetDescription() const override { return "ReadBarrierMarkSlowPathX86_64"; } |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 486 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 487 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 488 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 489 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 490 | Register ref_reg = ref_cpu_reg.AsRegister(); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 491 | DCHECK(locations->CanCall()); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 492 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 493 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 494 | instruction_->IsStaticFieldGet() || |
| 495 | instruction_->IsArrayGet() || |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 496 | instruction_->IsArraySet() || |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 497 | instruction_->IsLoadClass() || |
| 498 | instruction_->IsLoadString() || |
| 499 | instruction_->IsInstanceOf() || |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 500 | instruction_->IsCheckCast() || |
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 501 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 502 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 503 | << "Unexpected instruction in read barrier marking slow path: " |
| 504 | << instruction_->DebugName(); |
| 505 | |
| 506 | __ Bind(GetEntryLabel()); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 507 | if (unpoison_ref_before_marking_) { |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 508 | // Object* ref = ref_addr->AsMirrorPtr() |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 509 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 510 | } |
| Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 511 | // No need to save live registers; it's taken care of by the |
| 512 | // entrypoint. Also, there is no need to update the stack mask, |
| 513 | // as this runtime call will not trigger a garbage collection. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 514 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 515 | DCHECK_NE(ref_reg, RSP); |
| 516 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 517 | // "Compact" slow path, saving two moves. |
| 518 | // |
| 519 | // Instead of using the standard runtime calling convention (input |
| 520 | // and output in R0): |
| 521 | // |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 522 | // RDI <- ref |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 523 | // RAX <- ReadBarrierMark(RDI) |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 524 | // ref <- RAX |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 525 | // |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 526 | // we just use rX (the register containing `ref`) as input and output |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 527 | // of a dedicated entrypoint: |
| 528 | // |
| 529 | // rX <- ReadBarrierMarkRegX(rX) |
| 530 | // |
| 531 | int32_t entry_point_offset = |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 532 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 533 | // This runtime call does not require a stack map. |
| 534 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 535 | __ jmp(GetExitLabel()); |
| 536 | } |
| 537 | |
| 538 | private: |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 539 | // The location (register) of the marked object reference. |
| 540 | const Location ref_; |
| 541 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 542 | const bool unpoison_ref_before_marking_; |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 543 | |
| 544 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86_64); |
| 545 | }; |
| 546 | |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 547 | // Slow path marking an object reference `ref` during a read barrier, |
| 548 | // and if needed, atomically updating the field `obj.field` in the |
| 549 | // object `obj` holding this reference after marking (contrary to |
| 550 | // ReadBarrierMarkSlowPathX86_64 above, which never tries to update |
| 551 | // `obj.field`). |
| 552 | // |
| 553 | // This means that after the execution of this slow path, both `ref` |
| 554 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 555 | // hold the same to-space reference (unless another thread installed |
| 556 | // another object reference (different from `ref`) in `obj.field`). |
| 557 | class ReadBarrierMarkAndUpdateFieldSlowPathX86_64 : public SlowPathCode { |
| 558 | public: |
| 559 | ReadBarrierMarkAndUpdateFieldSlowPathX86_64(HInstruction* instruction, |
| 560 | Location ref, |
| 561 | CpuRegister obj, |
| 562 | const Address& field_addr, |
| 563 | bool unpoison_ref_before_marking, |
| 564 | CpuRegister temp1, |
| 565 | CpuRegister temp2) |
| 566 | : SlowPathCode(instruction), |
| 567 | ref_(ref), |
| 568 | obj_(obj), |
| 569 | field_addr_(field_addr), |
| 570 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 571 | temp1_(temp1), |
| 572 | temp2_(temp2) { |
| 573 | DCHECK(kEmitCompilerReadBarrier); |
| 574 | } |
| 575 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 576 | const char* GetDescription() const override { |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 577 | return "ReadBarrierMarkAndUpdateFieldSlowPathX86_64"; |
| 578 | } |
| 579 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 580 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 581 | LocationSummary* locations = instruction_->GetLocations(); |
| 582 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 583 | Register ref_reg = ref_cpu_reg.AsRegister(); |
| 584 | DCHECK(locations->CanCall()); |
| 585 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 586 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 587 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 588 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 589 | << instruction_->DebugName(); |
| 590 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 591 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 592 | |
| 593 | __ Bind(GetEntryLabel()); |
| 594 | if (unpoison_ref_before_marking_) { |
| 595 | // Object* ref = ref_addr->AsMirrorPtr() |
| 596 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
| 597 | } |
| 598 | |
| 599 | // Save the old (unpoisoned) reference. |
| 600 | __ movl(temp1_, ref_cpu_reg); |
| 601 | |
| 602 | // No need to save live registers; it's taken care of by the |
| 603 | // entrypoint. Also, there is no need to update the stack mask, |
| 604 | // as this runtime call will not trigger a garbage collection. |
| 605 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 606 | DCHECK_NE(ref_reg, RSP); |
| 607 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 608 | // "Compact" slow path, saving two moves. |
| 609 | // |
| 610 | // Instead of using the standard runtime calling convention (input |
| 611 | // and output in R0): |
| 612 | // |
| 613 | // RDI <- ref |
| 614 | // RAX <- ReadBarrierMark(RDI) |
| 615 | // ref <- RAX |
| 616 | // |
| 617 | // we just use rX (the register containing `ref`) as input and output |
| 618 | // of a dedicated entrypoint: |
| 619 | // |
| 620 | // rX <- ReadBarrierMarkRegX(rX) |
| 621 | // |
| 622 | int32_t entry_point_offset = |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 623 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 624 | // This runtime call does not require a stack map. |
| 625 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 626 | |
| 627 | // If the new reference is different from the old reference, |
| 628 | // update the field in the holder (`*field_addr`). |
| 629 | // |
| 630 | // Note that this field could also hold a different object, if |
| 631 | // another thread had concurrently changed it. In that case, the |
| 632 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 633 | // operation below would abort the CAS, leaving the field as-is. |
| 634 | NearLabel done; |
| 635 | __ cmpl(temp1_, ref_cpu_reg); |
| 636 | __ j(kEqual, &done); |
| 637 | |
| 638 | // Update the the holder's field atomically. This may fail if |
| 639 | // mutator updates before us, but it's OK. This is achived |
| 640 | // using a strong compare-and-set (CAS) operation with relaxed |
| 641 | // memory synchronization ordering, where the expected value is |
| 642 | // the old reference and the desired value is the new reference. |
| 643 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 644 | // instruction, which requires the expected value (the old |
| 645 | // reference) to be in EAX. Save RAX beforehand, and move the |
| 646 | // expected value (stored in `temp1_`) into EAX. |
| 647 | __ movq(temp2_, CpuRegister(RAX)); |
| 648 | __ movl(CpuRegister(RAX), temp1_); |
| 649 | |
| 650 | // Convenience aliases. |
| 651 | CpuRegister base = obj_; |
| 652 | CpuRegister expected = CpuRegister(RAX); |
| 653 | CpuRegister value = ref_cpu_reg; |
| 654 | |
| 655 | bool base_equals_value = (base.AsRegister() == value.AsRegister()); |
| 656 | Register value_reg = ref_reg; |
| 657 | if (kPoisonHeapReferences) { |
| 658 | if (base_equals_value) { |
| 659 | // If `base` and `value` are the same register location, move |
| 660 | // `value_reg` to a temporary register. This way, poisoning |
| 661 | // `value_reg` won't invalidate `base`. |
| 662 | value_reg = temp1_.AsRegister(); |
| 663 | __ movl(CpuRegister(value_reg), base); |
| 664 | } |
| 665 | |
| 666 | // Check that the register allocator did not assign the location |
| 667 | // of `expected` (RAX) to `value` nor to `base`, so that heap |
| 668 | // poisoning (when enabled) works as intended below. |
| 669 | // - If `value` were equal to `expected`, both references would |
| 670 | // be poisoned twice, meaning they would not be poisoned at |
| 671 | // all, as heap poisoning uses address negation. |
| 672 | // - If `base` were equal to `expected`, poisoning `expected` |
| 673 | // would invalidate `base`. |
| 674 | DCHECK_NE(value_reg, expected.AsRegister()); |
| 675 | DCHECK_NE(base.AsRegister(), expected.AsRegister()); |
| 676 | |
| 677 | __ PoisonHeapReference(expected); |
| 678 | __ PoisonHeapReference(CpuRegister(value_reg)); |
| 679 | } |
| 680 | |
| 681 | __ LockCmpxchgl(field_addr_, CpuRegister(value_reg)); |
| 682 | |
| 683 | // If heap poisoning is enabled, we need to unpoison the values |
| 684 | // that were poisoned earlier. |
| 685 | if (kPoisonHeapReferences) { |
| 686 | if (base_equals_value) { |
| 687 | // `value_reg` has been moved to a temporary register, no need |
| 688 | // to unpoison it. |
| 689 | } else { |
| 690 | __ UnpoisonHeapReference(CpuRegister(value_reg)); |
| 691 | } |
| 692 | // No need to unpoison `expected` (RAX), as it is be overwritten below. |
| 693 | } |
| 694 | |
| 695 | // Restore RAX. |
| 696 | __ movq(CpuRegister(RAX), temp2_); |
| 697 | |
| 698 | __ Bind(&done); |
| 699 | __ jmp(GetExitLabel()); |
| 700 | } |
| 701 | |
| 702 | private: |
| 703 | // The location (register) of the marked object reference. |
| 704 | const Location ref_; |
| 705 | // The register containing the object holding the marked object reference field. |
| 706 | const CpuRegister obj_; |
| 707 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 708 | const Address field_addr_; |
| 709 | |
| 710 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 711 | const bool unpoison_ref_before_marking_; |
| 712 | |
| 713 | const CpuRegister temp1_; |
| 714 | const CpuRegister temp2_; |
| 715 | |
| 716 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86_64); |
| 717 | }; |
| 718 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 719 | // Slow path generating a read barrier for a heap reference. |
| 720 | class ReadBarrierForHeapReferenceSlowPathX86_64 : public SlowPathCode { |
| 721 | public: |
| 722 | ReadBarrierForHeapReferenceSlowPathX86_64(HInstruction* instruction, |
| 723 | Location out, |
| 724 | Location ref, |
| 725 | Location obj, |
| 726 | uint32_t offset, |
| 727 | Location index) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 728 | : SlowPathCode(instruction), |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 729 | out_(out), |
| 730 | ref_(ref), |
| 731 | obj_(obj), |
| 732 | offset_(offset), |
| 733 | index_(index) { |
| 734 | DCHECK(kEmitCompilerReadBarrier); |
| 735 | // If `obj` is equal to `out` or `ref`, it means the initial |
| 736 | // object has been overwritten by (or after) the heap object |
| 737 | // reference load to be instrumented, e.g.: |
| 738 | // |
| 739 | // __ movl(out, Address(out, offset)); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 740 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 741 | // |
| 742 | // In that case, we have lost the information about the original |
| 743 | // object, and the emitted read barrier cannot work properly. |
| 744 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 745 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 746 | } |
| 747 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 748 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 749 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 750 | LocationSummary* locations = instruction_->GetLocations(); |
| 751 | CpuRegister reg_out = out_.AsRegister<CpuRegister>(); |
| 752 | DCHECK(locations->CanCall()); |
| 753 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.AsRegister())) << out_; |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 754 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 755 | instruction_->IsStaticFieldGet() || |
| 756 | instruction_->IsArrayGet() || |
| 757 | instruction_->IsInstanceOf() || |
| 758 | instruction_->IsCheckCast() || |
| Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 759 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 760 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 761 | << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 762 | |
| 763 | __ Bind(GetEntryLabel()); |
| 764 | SaveLiveRegisters(codegen, locations); |
| 765 | |
| 766 | // We may have to change the index's value, but as `index_` is a |
| 767 | // constant member (like other "inputs" of this slow path), |
| 768 | // introduce a copy of it, `index`. |
| 769 | Location index = index_; |
| 770 | if (index_.IsValid()) { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 771 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 772 | if (instruction_->IsArrayGet()) { |
| 773 | // Compute real offset and store it in index_. |
| 774 | Register index_reg = index_.AsRegister<CpuRegister>().AsRegister(); |
| 775 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 776 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 777 | // We are about to change the value of `index_reg` (see the |
| 778 | // calls to art::x86_64::X86_64Assembler::shll and |
| 779 | // art::x86_64::X86_64Assembler::AddImmediate below), but it |
| 780 | // has not been saved by the previous call to |
| 781 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 782 | // callee-save register -- |
| 783 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 784 | // callee-save registers, as it has been designed with the |
| 785 | // assumption that callee-save registers are supposed to be |
| 786 | // handled by the called function. So, as a callee-save |
| 787 | // register, `index_reg` _would_ eventually be saved onto |
| 788 | // the stack, but it would be too late: we would have |
| 789 | // changed its value earlier. Therefore, we manually save |
| 790 | // it here into another freely available register, |
| 791 | // `free_reg`, chosen of course among the caller-save |
| 792 | // registers (as a callee-save `free_reg` register would |
| 793 | // exhibit the same problem). |
| 794 | // |
| 795 | // Note we could have requested a temporary register from |
| 796 | // the register allocator instead; but we prefer not to, as |
| 797 | // this is a slow path, and we know we can find a |
| 798 | // caller-save register that is available. |
| 799 | Register free_reg = FindAvailableCallerSaveRegister(codegen).AsRegister(); |
| 800 | __ movl(CpuRegister(free_reg), CpuRegister(index_reg)); |
| 801 | index_reg = free_reg; |
| 802 | index = Location::RegisterLocation(index_reg); |
| 803 | } else { |
| 804 | // The initial register stored in `index_` has already been |
| 805 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 806 | // (as it is not a callee-save register), so we can freely |
| 807 | // use it. |
| 808 | } |
| 809 | // Shifting the index value contained in `index_reg` by the |
| 810 | // scale factor (2) cannot overflow in practice, as the |
| 811 | // runtime is unable to allocate object arrays with a size |
| 812 | // larger than 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 813 | __ shll(CpuRegister(index_reg), Immediate(TIMES_4)); |
| 814 | static_assert( |
| 815 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 816 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 817 | __ AddImmediate(CpuRegister(index_reg), Immediate(offset_)); |
| 818 | } else { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 819 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 820 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 821 | // (as in the case of ArrayGet), as it is actually an offset |
| 822 | // to an object field within an object. |
| 823 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 824 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 825 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 826 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 827 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 828 | DCHECK_EQ(offset_, 0U); |
| 829 | DCHECK(index_.IsRegister()); |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | // We're moving two or three locations to locations that could |
| 834 | // overlap, so we need a parallel move resolver. |
| 835 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 836 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 837 | parallel_move.AddMove(ref_, |
| 838 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 839 | DataType::Type::kReference, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 840 | nullptr); |
| 841 | parallel_move.AddMove(obj_, |
| 842 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 843 | DataType::Type::kReference, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 844 | nullptr); |
| 845 | if (index.IsValid()) { |
| 846 | parallel_move.AddMove(index, |
| 847 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 848 | DataType::Type::kInt32, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 849 | nullptr); |
| 850 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 851 | } else { |
| 852 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 853 | __ movl(CpuRegister(calling_convention.GetRegisterAt(2)), Immediate(offset_)); |
| 854 | } |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 855 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 856 | instruction_, |
| 857 | instruction_->GetDexPc(), |
| 858 | this); |
| 859 | CheckEntrypointTypes< |
| 860 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 861 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 862 | |
| 863 | RestoreLiveRegisters(codegen, locations); |
| 864 | __ jmp(GetExitLabel()); |
| 865 | } |
| 866 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 867 | const char* GetDescription() const override { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 868 | return "ReadBarrierForHeapReferenceSlowPathX86_64"; |
| 869 | } |
| 870 | |
| 871 | private: |
| 872 | CpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 873 | size_t ref = static_cast<int>(ref_.AsRegister<CpuRegister>().AsRegister()); |
| 874 | size_t obj = static_cast<int>(obj_.AsRegister<CpuRegister>().AsRegister()); |
| 875 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 876 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 877 | return static_cast<CpuRegister>(i); |
| 878 | } |
| 879 | } |
| 880 | // We shall never fail to find a free caller-save register, as |
| 881 | // there are more than two core caller-save registers on x86-64 |
| 882 | // (meaning it is possible to find one which is different from |
| 883 | // `ref` and `obj`). |
| 884 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 885 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 886 | UNREACHABLE(); |
| 887 | } |
| 888 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 889 | const Location out_; |
| 890 | const Location ref_; |
| 891 | const Location obj_; |
| 892 | const uint32_t offset_; |
| 893 | // An additional location containing an index to an array. |
| 894 | // Only used for HArrayGet and the UnsafeGetObject & |
| 895 | // UnsafeGetObjectVolatile intrinsics. |
| 896 | const Location index_; |
| 897 | |
| 898 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86_64); |
| 899 | }; |
| 900 | |
| 901 | // Slow path generating a read barrier for a GC root. |
| 902 | class ReadBarrierForRootSlowPathX86_64 : public SlowPathCode { |
| 903 | public: |
| 904 | ReadBarrierForRootSlowPathX86_64(HInstruction* instruction, Location out, Location root) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 905 | : SlowPathCode(instruction), out_(out), root_(root) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 906 | DCHECK(kEmitCompilerReadBarrier); |
| 907 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 908 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 909 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 910 | LocationSummary* locations = instruction_->GetLocations(); |
| 911 | DCHECK(locations->CanCall()); |
| 912 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 913 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 914 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 915 | << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 916 | |
| 917 | __ Bind(GetEntryLabel()); |
| 918 | SaveLiveRegisters(codegen, locations); |
| 919 | |
| 920 | InvokeRuntimeCallingConvention calling_convention; |
| 921 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 922 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 923 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 924 | instruction_, |
| 925 | instruction_->GetDexPc(), |
| 926 | this); |
| 927 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 928 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 929 | |
| 930 | RestoreLiveRegisters(codegen, locations); |
| 931 | __ jmp(GetExitLabel()); |
| 932 | } |
| 933 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 934 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathX86_64"; } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 935 | |
| 936 | private: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 937 | const Location out_; |
| 938 | const Location root_; |
| 939 | |
| 940 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86_64); |
| 941 | }; |
| 942 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 943 | #undef __ |
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 944 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 945 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> // NOLINT |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 946 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 947 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 948 | switch (cond) { |
| 949 | case kCondEQ: return kEqual; |
| 950 | case kCondNE: return kNotEqual; |
| 951 | case kCondLT: return kLess; |
| 952 | case kCondLE: return kLessEqual; |
| 953 | case kCondGT: return kGreater; |
| 954 | case kCondGE: return kGreaterEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 955 | case kCondB: return kBelow; |
| 956 | case kCondBE: return kBelowEqual; |
| 957 | case kCondA: return kAbove; |
| 958 | case kCondAE: return kAboveEqual; |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 959 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 960 | LOG(FATAL) << "Unreachable"; |
| 961 | UNREACHABLE(); |
| 962 | } |
| 963 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 964 | // Maps FP condition to x86_64 name. |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 965 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 966 | switch (cond) { |
| 967 | case kCondEQ: return kEqual; |
| 968 | case kCondNE: return kNotEqual; |
| 969 | case kCondLT: return kBelow; |
| 970 | case kCondLE: return kBelowEqual; |
| 971 | case kCondGT: return kAbove; |
| 972 | case kCondGE: return kAboveEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 973 | default: break; // should not happen |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 974 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 975 | LOG(FATAL) << "Unreachable"; |
| 976 | UNREACHABLE(); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 977 | } |
| 978 | |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 979 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86_64::GetSupportedInvokeStaticOrDirectDispatch( |
| 980 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 981 | ArtMethod* method ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 982 | return desired_dispatch_info; |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 983 | } |
| 984 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 985 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall( |
| 986 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 987 | // All registers are assumed to be correctly set up. |
| Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 988 | |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 989 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 990 | switch (invoke->GetMethodLoadKind()) { |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 991 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 992 | // temp = thread->string_init_entrypoint |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 993 | uint32_t offset = |
| 994 | GetThreadOffset<kX86_64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 995 | __ gs()->movq(temp.AsRegister<CpuRegister>(), Address::Absolute(offset, /* no_rip= */ true)); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 996 | break; |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 997 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 998 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 999 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1000 | break; |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1001 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: |
| 1002 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 1003 | __ leal(temp.AsRegister<CpuRegister>(), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1004 | Address::Absolute(kDummy32BitOffset, /* no_rip= */ false)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1005 | RecordBootImageMethodPatch(invoke); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1006 | break; |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1007 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
| 1008 | // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load. |
| 1009 | __ movl(temp.AsRegister<CpuRegister>(), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1010 | Address::Absolute(kDummy32BitOffset, /* no_rip= */ false)); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 1011 | RecordBootImageRelRoPatch(GetBootImageOffset(invoke)); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1012 | break; |
| 1013 | } |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1014 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1015 | __ movq(temp.AsRegister<CpuRegister>(), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1016 | Address::Absolute(kDummy32BitOffset, /* no_rip= */ false)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1017 | RecordMethodBssEntryPatch(invoke); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 1018 | // No need for memory fence, thanks to the x86-64 memory model. |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1019 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1020 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 1021 | case HInvokeStaticOrDirect::MethodLoadKind::kJitDirectAddress: |
| 1022 | Load64BitValue(temp.AsRegister<CpuRegister>(), invoke->GetMethodAddress()); |
| 1023 | break; |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1024 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 1025 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 1026 | return; // No code pointer retrieval; the runtime performs the call directly. |
| Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 1027 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | switch (invoke->GetCodePtrLocation()) { |
| 1031 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 1032 | __ call(&frame_entry_label_); |
| 1033 | break; |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1034 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 1035 | // (callee_method + offset_of_quick_compiled_code)() |
| 1036 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 1037 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1038 | kX86_64PointerSize).SizeValue())); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1039 | break; |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1040 | } |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1041 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1042 | |
| 1043 | DCHECK(!IsLeafMethod()); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1044 | } |
| 1045 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1046 | void CodeGeneratorX86_64::GenerateVirtualCall( |
| 1047 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1048 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 1049 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 1050 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1051 | |
| 1052 | // Use the calling convention instead of the location of the receiver, as |
| 1053 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 1054 | // slow path, the arguments have been moved to the right place, so here we are |
| 1055 | // guaranteed that the receiver is the first register of the calling convention. |
| 1056 | InvokeDexCallingConvention calling_convention; |
| 1057 | Register receiver = calling_convention.GetRegisterAt(0); |
| 1058 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1059 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1060 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1061 | __ movl(temp, Address(CpuRegister(receiver), class_offset)); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1062 | MaybeRecordImplicitNullCheck(invoke); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1063 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 1064 | // emit a read barrier for the previous class reference load. |
| 1065 | // However this is not required in practice, as this is an |
| 1066 | // intermediate/temporary reference and because the current |
| 1067 | // concurrent copying collector keeps the from-space memory |
| 1068 | // intact/accessible until the end of the marking phase (the |
| 1069 | // concurrent copying collector may not in the future). |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1070 | __ MaybeUnpoisonHeapReference(temp); |
| 1071 | // temp = temp->GetMethodAt(method_offset); |
| 1072 | __ movq(temp, Address(temp, method_offset)); |
| 1073 | // call temp->GetEntryPoint(); |
| 1074 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1075 | kX86_64PointerSize).SizeValue())); |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1076 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1077 | } |
| 1078 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1079 | void CodeGeneratorX86_64::RecordBootImageIntrinsicPatch(uint32_t intrinsic_data) { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1080 | boot_image_other_patches_.emplace_back(/* target_dex_file= */ nullptr, intrinsic_data); |
| 1081 | __ Bind(&boot_image_other_patches_.back().label); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1082 | } |
| 1083 | |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1084 | void CodeGeneratorX86_64::RecordBootImageRelRoPatch(uint32_t boot_image_offset) { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1085 | boot_image_other_patches_.emplace_back(/* target_dex_file= */ nullptr, boot_image_offset); |
| 1086 | __ Bind(&boot_image_other_patches_.back().label); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1087 | } |
| 1088 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1089 | void CodeGeneratorX86_64::RecordBootImageMethodPatch(HInvokeStaticOrDirect* invoke) { |
| 1090 | boot_image_method_patches_.emplace_back( |
| 1091 | invoke->GetTargetMethod().dex_file, invoke->GetTargetMethod().index); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1092 | __ Bind(&boot_image_method_patches_.back().label); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1095 | void CodeGeneratorX86_64::RecordMethodBssEntryPatch(HInvokeStaticOrDirect* invoke) { |
| 1096 | method_bss_entry_patches_.emplace_back(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 1097 | __ Bind(&method_bss_entry_patches_.back().label); |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1098 | } |
| 1099 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1100 | void CodeGeneratorX86_64::RecordBootImageTypePatch(HLoadClass* load_class) { |
| 1101 | boot_image_type_patches_.emplace_back( |
| 1102 | &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1103 | __ Bind(&boot_image_type_patches_.back().label); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1104 | } |
| 1105 | |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1106 | Label* CodeGeneratorX86_64::NewTypeBssEntryPatch(HLoadClass* load_class) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1107 | type_bss_entry_patches_.emplace_back( |
| 1108 | &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1109 | return &type_bss_entry_patches_.back().label; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1112 | void CodeGeneratorX86_64::RecordBootImageStringPatch(HLoadString* load_string) { |
| 1113 | boot_image_string_patches_.emplace_back( |
| 1114 | &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| 1115 | __ Bind(&boot_image_string_patches_.back().label); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1116 | } |
| 1117 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1118 | Label* CodeGeneratorX86_64::NewStringBssEntryPatch(HLoadString* load_string) { |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1119 | string_bss_entry_patches_.emplace_back( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1120 | &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1121 | return &string_bss_entry_patches_.back().label; |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1122 | } |
| 1123 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1124 | void CodeGeneratorX86_64::LoadBootImageAddress(CpuRegister reg, uint32_t boot_image_reference) { |
| 1125 | if (GetCompilerOptions().IsBootImage()) { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1126 | __ leal(reg, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip= */ false)); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1127 | RecordBootImageIntrinsicPatch(boot_image_reference); |
| Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 1128 | } else if (GetCompilerOptions().GetCompilePic()) { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1129 | __ movl(reg, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip= */ false)); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1130 | RecordBootImageRelRoPatch(boot_image_reference); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1131 | } else { |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 1132 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1133 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 1134 | DCHECK(!heap->GetBootImageSpaces().empty()); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1135 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1136 | __ movl(reg, Immediate(dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(address)))); |
| 1137 | } |
| 1138 | } |
| 1139 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1140 | void CodeGeneratorX86_64::AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, |
| 1141 | uint32_t boot_image_offset) { |
| 1142 | DCHECK(invoke->IsStatic()); |
| 1143 | InvokeRuntimeCallingConvention calling_convention; |
| 1144 | CpuRegister argument = CpuRegister(calling_convention.GetRegisterAt(0)); |
| 1145 | if (GetCompilerOptions().IsBootImage()) { |
| 1146 | DCHECK_EQ(boot_image_offset, IntrinsicVisitor::IntegerValueOfInfo::kInvalidReference); |
| 1147 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
| 1148 | __ leal(argument, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1149 | Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip= */ false)); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1150 | MethodReference target_method = invoke->GetTargetMethod(); |
| 1151 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 1152 | boot_image_type_patches_.emplace_back(target_method.dex_file, type_idx.index_); |
| 1153 | __ Bind(&boot_image_type_patches_.back().label); |
| 1154 | } else { |
| 1155 | LoadBootImageAddress(argument, boot_image_offset); |
| 1156 | } |
| 1157 | InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); |
| 1158 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 1159 | } |
| 1160 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1161 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 1162 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 1163 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 1164 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1165 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1166 | inline void CodeGeneratorX86_64::EmitPcRelativeLinkerPatches( |
| 1167 | const ArenaDeque<PatchInfo<Label>>& infos, |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1168 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1169 | for (const PatchInfo<Label>& info : infos) { |
| 1170 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 1171 | linker_patches->push_back( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1172 | Factory(literal_offset, info.target_dex_file, info.label.Position(), info.offset_or_index)); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1173 | } |
| 1174 | } |
| 1175 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1176 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 1177 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 1178 | const DexFile* target_dex_file, |
| 1179 | uint32_t pc_insn_offset, |
| 1180 | uint32_t boot_image_offset) { |
| 1181 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 1182 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1183 | } |
| 1184 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1185 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1186 | DCHECK(linker_patches->empty()); |
| 1187 | size_t size = |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1188 | boot_image_method_patches_.size() + |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1189 | method_bss_entry_patches_.size() + |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1190 | boot_image_type_patches_.size() + |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1191 | type_bss_entry_patches_.size() + |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1192 | boot_image_string_patches_.size() + |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1193 | string_bss_entry_patches_.size() + |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1194 | boot_image_other_patches_.size(); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1195 | linker_patches->reserve(size); |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 1196 | if (GetCompilerOptions().IsBootImage()) { |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1197 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 1198 | boot_image_method_patches_, linker_patches); |
| 1199 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 1200 | boot_image_type_patches_, linker_patches); |
| 1201 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1202 | boot_image_string_patches_, linker_patches); |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 1203 | } else { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1204 | DCHECK(boot_image_method_patches_.empty()); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 1205 | DCHECK(boot_image_type_patches_.empty()); |
| 1206 | DCHECK(boot_image_string_patches_.empty()); |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1207 | } |
| 1208 | if (GetCompilerOptions().IsBootImage()) { |
| 1209 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 1210 | boot_image_other_patches_, linker_patches); |
| 1211 | } else { |
| 1212 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 1213 | boot_image_other_patches_, linker_patches); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1214 | } |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1215 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 1216 | method_bss_entry_patches_, linker_patches); |
| 1217 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 1218 | type_bss_entry_patches_, linker_patches); |
| 1219 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 1220 | string_bss_entry_patches_, linker_patches); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1221 | DCHECK_EQ(size, linker_patches->size()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1222 | } |
| 1223 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1224 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1225 | stream << Register(reg); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1229 | stream << FloatRegister(reg); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1230 | } |
| 1231 | |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1232 | const X86_64InstructionSetFeatures& CodeGeneratorX86_64::GetInstructionSetFeatures() const { |
| 1233 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsX86_64InstructionSetFeatures(); |
| 1234 | } |
| 1235 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1236 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1237 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 1238 | return kX86_64WordSize; |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1239 | } |
| 1240 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1241 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1242 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1243 | return kX86_64WordSize; |
| 1244 | } |
| 1245 | |
| 1246 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1247 | if (GetGraph()->HasSIMD()) { |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1248 | __ movups(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1249 | } else { |
| 1250 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 1251 | } |
| 1252 | return GetFloatingPointSpillSlotSize(); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1256 | if (GetGraph()->HasSIMD()) { |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1257 | __ movups(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1258 | } else { |
| 1259 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1260 | } |
| 1261 | return GetFloatingPointSpillSlotSize(); |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1262 | } |
| 1263 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1264 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1265 | HInstruction* instruction, |
| 1266 | uint32_t dex_pc, |
| 1267 | SlowPathCode* slow_path) { |
| Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1268 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1269 | GenerateInvokeRuntime(GetThreadOffset<kX86_64PointerSize>(entrypoint).Int32Value()); |
| 1270 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1271 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1272 | } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1273 | } |
| 1274 | |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1275 | void CodeGeneratorX86_64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1276 | HInstruction* instruction, |
| 1277 | SlowPathCode* slow_path) { |
| 1278 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1279 | GenerateInvokeRuntime(entry_point_offset); |
| 1280 | } |
| 1281 | |
| 1282 | void CodeGeneratorX86_64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1283 | __ gs()->call(Address::Absolute(entry_point_offset, /* no_rip= */ true)); |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1284 | } |
| 1285 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1286 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1287 | // Use a fake return address register to mimic Quick. |
| 1288 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1289 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1290 | const CompilerOptions& compiler_options, |
| 1291 | OptimizingCompilerStats* stats) |
| Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1292 | : CodeGenerator(graph, |
| 1293 | kNumberOfCpuRegisters, |
| 1294 | kNumberOfFloatRegisters, |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1295 | kNumberOfCpuRegisterPairs, |
| Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1296 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1297 | arraysize(kCoreCalleeSaves)) |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1298 | | (1 << kFakeReturnRegister), |
| Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1299 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1300 | arraysize(kFpuCalleeSaves)), |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1301 | compiler_options, |
| 1302 | stats), |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1303 | block_labels_(nullptr), |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1304 | location_builder_(graph, this), |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1305 | instruction_visitor_(graph, this), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1306 | move_resolver_(graph->GetAllocator(), this), |
| 1307 | assembler_(graph->GetAllocator()), |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1308 | constant_area_start_(0), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1309 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1310 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1311 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1312 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1313 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1314 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1315 | boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1316 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1317 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1318 | fixups_to_jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1319 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 1320 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1321 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1322 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 1323 | CodeGeneratorX86_64* codegen) |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1324 | : InstructionCodeGenerator(graph, codegen), |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1325 | assembler_(codegen->GetAssembler()), |
| 1326 | codegen_(codegen) {} |
| 1327 | |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1328 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1329 | // Stack register is always reserved. |
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1330 | blocked_core_registers_[RSP] = true; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1331 | |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1332 | // Block the register used as TMP. |
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1333 | blocked_core_registers_[TMP] = true; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1334 | } |
| 1335 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1336 | static dwarf::Reg DWARFReg(Register reg) { |
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1337 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1338 | } |
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1339 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1340 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1341 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1342 | } |
| 1343 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1344 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1345 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1346 | __ Bind(&frame_entry_label_); |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1347 | bool skip_overflow_check = IsLeafMethod() |
| Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 1348 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1349 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1350 | |
| Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1351 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1352 | __ addw(Address(CpuRegister(kMethodRegisterArgument), |
| 1353 | ArtMethod::HotnessCountOffset().Int32Value()), |
| 1354 | Immediate(1)); |
| 1355 | } |
| 1356 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1357 | if (!skip_overflow_check) { |
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1358 | size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86_64); |
| 1359 | __ testq(CpuRegister(RAX), Address(CpuRegister(RSP), -static_cast<int32_t>(reserved_bytes))); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1360 | RecordPcInfo(nullptr, 0); |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1361 | } |
| Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 1362 | |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1363 | if (HasEmptyFrame()) { |
| 1364 | return; |
| 1365 | } |
| 1366 | |
| Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1367 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1368 | Register reg = kCoreCalleeSaves[i]; |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1369 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1370 | __ pushq(CpuRegister(reg)); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1371 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1372 | __ cfi().RelOffset(DWARFReg(reg), 0); |
| Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1373 | } |
| 1374 | } |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1375 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1376 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1377 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 1378 | __ cfi().AdjustCFAOffset(adjust); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1379 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1380 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1381 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1382 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1383 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1384 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1385 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1386 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1387 | } |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1388 | } |
| 1389 | |
| Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1390 | // Save the current method if we need it. Note that we do not |
| 1391 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1392 | // in the SSA graph. |
| 1393 | if (RequiresCurrentMethod()) { |
| 1394 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
| 1395 | CpuRegister(kMethodRegisterArgument)); |
| 1396 | } |
| Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 1397 | |
| 1398 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1399 | // Initialize should_deoptimize flag to 0. |
| 1400 | __ movl(Address(CpuRegister(RSP), GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
| 1401 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | void CodeGeneratorX86_64::GenerateFrameExit() { |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1405 | __ cfi().RememberState(); |
| 1406 | if (!HasEmptyFrame()) { |
| 1407 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1408 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 1409 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1410 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1411 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1412 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1413 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1414 | } |
| 1415 | } |
| 1416 | |
| 1417 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1418 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 1419 | __ cfi().AdjustCFAOffset(-adjust); |
| 1420 | |
| 1421 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1422 | Register reg = kCoreCalleeSaves[i]; |
| 1423 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1424 | __ popq(CpuRegister(reg)); |
| 1425 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1426 | __ cfi().Restore(DWARFReg(reg)); |
| 1427 | } |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1428 | } |
| 1429 | } |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1430 | __ ret(); |
| 1431 | __ cfi().RestoreState(); |
| 1432 | __ cfi().DefCFAOffset(GetFrameSize()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1433 | } |
| 1434 | |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1435 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1436 | __ Bind(GetLabelOf(block)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1437 | } |
| 1438 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1439 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1440 | if (source.Equals(destination)) { |
| 1441 | return; |
| 1442 | } |
| 1443 | if (destination.IsRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1444 | CpuRegister dest = destination.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1445 | if (source.IsRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1446 | __ movq(dest, source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1447 | } else if (source.IsFpuRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1448 | __ movd(dest, source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1449 | } else if (source.IsStackSlot()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1450 | __ movl(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1451 | } else if (source.IsConstant()) { |
| 1452 | HConstant* constant = source.GetConstant(); |
| 1453 | if (constant->IsLongConstant()) { |
| 1454 | Load64BitValue(dest, constant->AsLongConstant()->GetValue()); |
| 1455 | } else { |
| 1456 | Load32BitValue(dest, GetInt32ValueOf(constant)); |
| 1457 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1458 | } else { |
| 1459 | DCHECK(source.IsDoubleStackSlot()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1460 | __ movq(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1461 | } |
| 1462 | } else if (destination.IsFpuRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1463 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1464 | if (source.IsRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1465 | __ movd(dest, source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1466 | } else if (source.IsFpuRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1467 | __ movaps(dest, source.AsFpuRegister<XmmRegister>()); |
| 1468 | } else if (source.IsConstant()) { |
| 1469 | HConstant* constant = source.GetConstant(); |
| 1470 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 1471 | if (constant->IsFloatConstant()) { |
| 1472 | Load32BitValue(dest, static_cast<int32_t>(value)); |
| 1473 | } else { |
| 1474 | Load64BitValue(dest, value); |
| 1475 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1476 | } else if (source.IsStackSlot()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1477 | __ movss(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1478 | } else { |
| 1479 | DCHECK(source.IsDoubleStackSlot()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1480 | __ movsd(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1481 | } |
| 1482 | } else if (destination.IsStackSlot()) { |
| 1483 | if (source.IsRegister()) { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1484 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1485 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1486 | } else if (source.IsFpuRegister()) { |
| 1487 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1488 | source.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1489 | } else if (source.IsConstant()) { |
| 1490 | HConstant* constant = source.GetConstant(); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1491 | int32_t value = GetInt32ValueOf(constant); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1492 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1493 | } else { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1494 | DCHECK(source.IsStackSlot()) << source; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1495 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1496 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1497 | } |
| 1498 | } else { |
| 1499 | DCHECK(destination.IsDoubleStackSlot()); |
| 1500 | if (source.IsRegister()) { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1501 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1502 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1503 | } else if (source.IsFpuRegister()) { |
| 1504 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1505 | source.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1506 | } else if (source.IsConstant()) { |
| 1507 | HConstant* constant = source.GetConstant(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1508 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1509 | int64_t value = GetInt64ValueOf(constant); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1510 | Store64BitValueToStack(destination, value); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1511 | } else { |
| 1512 | DCHECK(source.IsDoubleStackSlot()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1513 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1514 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1515 | } |
| 1516 | } |
| 1517 | } |
| 1518 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1519 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1520 | DCHECK(location.IsRegister()); |
| 1521 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1522 | } |
| 1523 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1524 | void CodeGeneratorX86_64::MoveLocation( |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1525 | Location dst, Location src, DataType::Type dst_type ATTRIBUTE_UNUSED) { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1526 | Move(dst, src); |
| 1527 | } |
| 1528 | |
| 1529 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1530 | if (location.IsRegister()) { |
| 1531 | locations->AddTemp(location); |
| 1532 | } else { |
| 1533 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1534 | } |
| 1535 | } |
| 1536 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1537 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 1538 | if (successor->IsExitBlock()) { |
| 1539 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 1540 | return; // no code needed |
| 1541 | } |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1542 | |
| 1543 | HBasicBlock* block = got->GetBlock(); |
| 1544 | HInstruction* previous = got->GetPrevious(); |
| 1545 | |
| 1546 | HLoopInformation* info = block->GetLoopInformation(); |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1547 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1548 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1549 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), 0)); |
| 1550 | __ addw(Address(CpuRegister(TMP), ArtMethod::HotnessCountOffset().Int32Value()), |
| 1551 | Immediate(1)); |
| 1552 | } |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1553 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1554 | return; |
| 1555 | } |
| 1556 | |
| 1557 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1558 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1559 | } |
| 1560 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1561 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1562 | } |
| 1563 | } |
| 1564 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1565 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1566 | got->SetLocations(nullptr); |
| 1567 | } |
| 1568 | |
| 1569 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1570 | HandleGoto(got, got->GetSuccessor()); |
| 1571 | } |
| 1572 | |
| 1573 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1574 | try_boundary->SetLocations(nullptr); |
| 1575 | } |
| 1576 | |
| 1577 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1578 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1579 | if (!successor->IsExitBlock()) { |
| 1580 | HandleGoto(try_boundary, successor); |
| 1581 | } |
| 1582 | } |
| 1583 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1584 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1585 | exit->SetLocations(nullptr); |
| 1586 | } |
| 1587 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1588 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1589 | } |
| 1590 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1591 | template<class LabelType> |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1592 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1593 | LabelType* true_label, |
| 1594 | LabelType* false_label) { |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1595 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1596 | __ j(kUnordered, true_label); |
| 1597 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1598 | __ j(kUnordered, false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1599 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1600 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1601 | } |
| 1602 | |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1603 | void InstructionCodeGeneratorX86_64::GenerateCompareTest(HCondition* condition) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1604 | LocationSummary* locations = condition->GetLocations(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1605 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1606 | Location left = locations->InAt(0); |
| 1607 | Location right = locations->InAt(1); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1608 | DataType::Type type = condition->InputAt(0)->GetType(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1609 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1610 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1611 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1612 | case DataType::Type::kInt8: |
| 1613 | case DataType::Type::kUint16: |
| 1614 | case DataType::Type::kInt16: |
| 1615 | case DataType::Type::kInt32: |
| 1616 | case DataType::Type::kReference: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1617 | codegen_->GenerateIntCompare(left, right); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1618 | break; |
| 1619 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1620 | case DataType::Type::kInt64: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1621 | codegen_->GenerateLongCompare(left, right); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1622 | break; |
| 1623 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1624 | case DataType::Type::kFloat32: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1625 | if (right.IsFpuRegister()) { |
| 1626 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1627 | } else if (right.IsConstant()) { |
| 1628 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1629 | codegen_->LiteralFloatAddress( |
| 1630 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1631 | } else { |
| 1632 | DCHECK(right.IsStackSlot()); |
| 1633 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1634 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1635 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1636 | break; |
| 1637 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1638 | case DataType::Type::kFloat64: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1639 | if (right.IsFpuRegister()) { |
| 1640 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1641 | } else if (right.IsConstant()) { |
| 1642 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1643 | codegen_->LiteralDoubleAddress( |
| 1644 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1645 | } else { |
| 1646 | DCHECK(right.IsDoubleStackSlot()); |
| 1647 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1648 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1649 | } |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1650 | break; |
| 1651 | } |
| 1652 | default: |
| 1653 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1654 | } |
| 1655 | } |
| 1656 | |
| 1657 | template<class LabelType> |
| 1658 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1659 | LabelType* true_target_in, |
| 1660 | LabelType* false_target_in) { |
| 1661 | // Generated branching requires both targets to be explicit. If either of the |
| 1662 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1663 | LabelType fallthrough_target; |
| 1664 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1665 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1666 | |
| 1667 | // Generate the comparison to set the CC. |
| 1668 | GenerateCompareTest(condition); |
| 1669 | |
| 1670 | // Now generate the correct jump(s). |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1671 | DataType::Type type = condition->InputAt(0)->GetType(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1672 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1673 | case DataType::Type::kInt64: { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1674 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| 1675 | break; |
| 1676 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1677 | case DataType::Type::kFloat32: { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1678 | GenerateFPJumps(condition, true_target, false_target); |
| 1679 | break; |
| 1680 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1681 | case DataType::Type::kFloat64: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1682 | GenerateFPJumps(condition, true_target, false_target); |
| 1683 | break; |
| 1684 | } |
| 1685 | default: |
| 1686 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1687 | } |
| 1688 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1689 | if (false_target != &fallthrough_target) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1690 | __ jmp(false_target); |
| 1691 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1692 | |
| 1693 | if (fallthrough_target.IsLinked()) { |
| 1694 | __ Bind(&fallthrough_target); |
| 1695 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1696 | } |
| 1697 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1698 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1699 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1700 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1701 | // conditions if they are materialized due to the complex branching. |
| 1702 | return cond->IsCondition() && |
| 1703 | cond->GetNext() == branch && |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1704 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1705 | } |
| 1706 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1707 | template<class LabelType> |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1708 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1709 | size_t condition_input_index, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1710 | LabelType* true_target, |
| 1711 | LabelType* false_target) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1712 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1713 | |
| 1714 | if (true_target == nullptr && false_target == nullptr) { |
| 1715 | // Nothing to do. The code always falls through. |
| 1716 | return; |
| 1717 | } else if (cond->IsIntConstant()) { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1718 | // Constant condition, statically compared against "true" (integer value 1). |
| 1719 | if (cond->AsIntConstant()->IsTrue()) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1720 | if (true_target != nullptr) { |
| 1721 | __ jmp(true_target); |
| Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1722 | } |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1723 | } else { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1724 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1725 | if (false_target != nullptr) { |
| 1726 | __ jmp(false_target); |
| 1727 | } |
| 1728 | } |
| 1729 | return; |
| 1730 | } |
| 1731 | |
| 1732 | // The following code generates these patterns: |
| 1733 | // (1) true_target == nullptr && false_target != nullptr |
| 1734 | // - opposite condition true => branch to false_target |
| 1735 | // (2) true_target != nullptr && false_target == nullptr |
| 1736 | // - condition true => branch to true_target |
| 1737 | // (3) true_target != nullptr && false_target != nullptr |
| 1738 | // - condition true => branch to true_target |
| 1739 | // - branch to false_target |
| 1740 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1741 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1742 | if (true_target == nullptr) { |
| 1743 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1744 | } else { |
| 1745 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1746 | } |
| 1747 | } else { |
| 1748 | // Materialized condition, compare against 0. |
| 1749 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1750 | if (lhs.IsRegister()) { |
| 1751 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1752 | } else { |
| 1753 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1754 | } |
| 1755 | if (true_target == nullptr) { |
| 1756 | __ j(kEqual, false_target); |
| 1757 | } else { |
| 1758 | __ j(kNotEqual, true_target); |
| 1759 | } |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1760 | } |
| 1761 | } else { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1762 | // Condition has not been materialized, use its inputs as the |
| 1763 | // comparison and its condition as the branch condition. |
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1764 | HCondition* condition = cond->AsCondition(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1765 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1766 | // If this is a long or FP comparison that has been folded into |
| 1767 | // the HCondition, generate the comparison directly. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1768 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 1769 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1770 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1771 | return; |
| 1772 | } |
| 1773 | |
| 1774 | Location lhs = condition->GetLocations()->InAt(0); |
| 1775 | Location rhs = condition->GetLocations()->InAt(1); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1776 | codegen_->GenerateIntCompare(lhs, rhs); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1777 | if (true_target == nullptr) { |
| 1778 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1779 | } else { |
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1780 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1781 | } |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1782 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1783 | |
| 1784 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1785 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1786 | if (true_target != nullptr && false_target != nullptr) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1787 | __ jmp(false_target); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1788 | } |
| 1789 | } |
| 1790 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1791 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1792 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1793 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1794 | locations->SetInAt(0, Location::Any()); |
| 1795 | } |
| 1796 | } |
| 1797 | |
| 1798 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1799 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1800 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1801 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1802 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1803 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1804 | nullptr : codegen_->GetLabelOf(false_successor); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1805 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1809 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1810 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1811 | InvokeRuntimeCallingConvention calling_convention; |
| 1812 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1813 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1814 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1815 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1816 | locations->SetInAt(0, Location::Any()); |
| 1817 | } |
| 1818 | } |
| 1819 | |
| 1820 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1821 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1822 | GenerateTestAndBranch<Label>(deoptimize, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1823 | /* condition_input_index= */ 0, |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1824 | slow_path->GetEntryLabel(), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1825 | /* false_target= */ nullptr); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1826 | } |
| 1827 | |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1828 | void LocationsBuilderX86_64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1829 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1830 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1831 | locations->SetOut(Location::RequiresRegister()); |
| 1832 | } |
| 1833 | |
| 1834 | void InstructionCodeGeneratorX86_64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1835 | __ movl(flag->GetLocations()->Out().AsRegister<CpuRegister>(), |
| 1836 | Address(CpuRegister(RSP), codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1837 | } |
| 1838 | |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1839 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1840 | // There are no conditional move instructions for XMMs. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1841 | if (DataType::IsFloatingPointType(select->GetType())) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1842 | return false; |
| 1843 | } |
| 1844 | |
| 1845 | // A FP condition doesn't generate the single CC that we need. |
| 1846 | HInstruction* condition = select->GetCondition(); |
| 1847 | if (condition->IsCondition() && |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1848 | DataType::IsFloatingPointType(condition->InputAt(0)->GetType())) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1849 | return false; |
| 1850 | } |
| 1851 | |
| 1852 | // We can generate a CMOV for this Select. |
| 1853 | return true; |
| 1854 | } |
| 1855 | |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1856 | void LocationsBuilderX86_64::VisitSelect(HSelect* select) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1857 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1858 | if (DataType::IsFloatingPointType(select->GetType())) { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1859 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1860 | locations->SetInAt(1, Location::Any()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1861 | } else { |
| 1862 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1863 | if (SelectCanUseCMOV(select)) { |
| Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1864 | if (select->InputAt(1)->IsConstant()) { |
| 1865 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1866 | } else { |
| 1867 | locations->SetInAt(1, Location::Any()); |
| 1868 | } |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1869 | } else { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1870 | locations->SetInAt(1, Location::Any()); |
| 1871 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1872 | } |
| 1873 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1874 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1875 | } |
| 1876 | locations->SetOut(Location::SameAsFirstInput()); |
| 1877 | } |
| 1878 | |
| 1879 | void InstructionCodeGeneratorX86_64::VisitSelect(HSelect* select) { |
| 1880 | LocationSummary* locations = select->GetLocations(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1881 | if (SelectCanUseCMOV(select)) { |
| 1882 | // If both the condition and the source types are integer, we can generate |
| 1883 | // a CMOV to implement Select. |
| 1884 | CpuRegister value_false = locations->InAt(0).AsRegister<CpuRegister>(); |
| Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1885 | Location value_true_loc = locations->InAt(1); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1886 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1887 | |
| 1888 | HInstruction* select_condition = select->GetCondition(); |
| 1889 | Condition cond = kNotEqual; |
| 1890 | |
| 1891 | // Figure out how to test the 'condition'. |
| 1892 | if (select_condition->IsCondition()) { |
| 1893 | HCondition* condition = select_condition->AsCondition(); |
| 1894 | if (!condition->IsEmittedAtUseSite()) { |
| 1895 | // This was a previously materialized condition. |
| 1896 | // Can we use the existing condition code? |
| 1897 | if (AreEflagsSetFrom(condition, select)) { |
| 1898 | // Materialization was the previous instruction. Condition codes are right. |
| 1899 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1900 | } else { |
| 1901 | // No, we have to recreate the condition code. |
| 1902 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1903 | __ testl(cond_reg, cond_reg); |
| 1904 | } |
| 1905 | } else { |
| 1906 | GenerateCompareTest(condition); |
| 1907 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1908 | } |
| 1909 | } else { |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1910 | // Must be a Boolean condition, which needs to be compared to 0. |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1911 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1912 | __ testl(cond_reg, cond_reg); |
| 1913 | } |
| 1914 | |
| 1915 | // If the condition is true, overwrite the output, which already contains false. |
| 1916 | // Generate the correct sized CMOV. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1917 | bool is_64_bit = DataType::Is64BitType(select->GetType()); |
| Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1918 | if (value_true_loc.IsRegister()) { |
| 1919 | __ cmov(cond, value_false, value_true_loc.AsRegister<CpuRegister>(), is_64_bit); |
| 1920 | } else { |
| 1921 | __ cmov(cond, |
| 1922 | value_false, |
| 1923 | Address(CpuRegister(RSP), value_true_loc.GetStackIndex()), is_64_bit); |
| 1924 | } |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1925 | } else { |
| 1926 | NearLabel false_target; |
| 1927 | GenerateTestAndBranch<NearLabel>(select, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1928 | /* condition_input_index= */ 2, |
| 1929 | /* true_target= */ nullptr, |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1930 | &false_target); |
| 1931 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1932 | __ Bind(&false_target); |
| 1933 | } |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1934 | } |
| 1935 | |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1936 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1937 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1938 | } |
| 1939 | |
| David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1940 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1941 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1942 | } |
| 1943 | |
| 1944 | void CodeGeneratorX86_64::GenerateNop() { |
| 1945 | __ nop(); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1946 | } |
| 1947 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1948 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1949 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1950 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1951 | // Handle the long/FP comparisons made in instruction simplification. |
| 1952 | switch (cond->InputAt(0)->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1953 | case DataType::Type::kInt64: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1954 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1955 | locations->SetInAt(1, Location::Any()); |
| 1956 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1957 | case DataType::Type::kFloat32: |
| 1958 | case DataType::Type::kFloat64: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1959 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1960 | locations->SetInAt(1, Location::Any()); |
| 1961 | break; |
| 1962 | default: |
| 1963 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1964 | locations->SetInAt(1, Location::Any()); |
| 1965 | break; |
| 1966 | } |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1967 | if (!cond->IsEmittedAtUseSite()) { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1968 | locations->SetOut(Location::RequiresRegister()); |
| 1969 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1970 | } |
| 1971 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1972 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1973 | if (cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1974 | return; |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1975 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1976 | |
| 1977 | LocationSummary* locations = cond->GetLocations(); |
| 1978 | Location lhs = locations->InAt(0); |
| 1979 | Location rhs = locations->InAt(1); |
| 1980 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1981 | NearLabel true_label, false_label; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1982 | |
| 1983 | switch (cond->InputAt(0)->GetType()) { |
| 1984 | default: |
| 1985 | // Integer case. |
| 1986 | |
| 1987 | // Clear output register: setcc only sets the low byte. |
| 1988 | __ xorl(reg, reg); |
| 1989 | |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1990 | codegen_->GenerateIntCompare(lhs, rhs); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1991 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1992 | return; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1993 | case DataType::Type::kInt64: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1994 | // Clear output register: setcc only sets the low byte. |
| 1995 | __ xorl(reg, reg); |
| 1996 | |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1997 | codegen_->GenerateLongCompare(lhs, rhs); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1998 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1999 | return; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2000 | case DataType::Type::kFloat32: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2001 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 2002 | if (rhs.IsConstant()) { |
| 2003 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 2004 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 2005 | } else if (rhs.IsStackSlot()) { |
| 2006 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 2007 | } else { |
| 2008 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 2009 | } |
| 2010 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2011 | break; |
| 2012 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2013 | case DataType::Type::kFloat64: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2014 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 2015 | if (rhs.IsConstant()) { |
| 2016 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2017 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 2018 | } else if (rhs.IsDoubleStackSlot()) { |
| 2019 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 2020 | } else { |
| 2021 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 2022 | } |
| 2023 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2024 | break; |
| 2025 | } |
| 2026 | } |
| 2027 | |
| 2028 | // Convert the jumps into the result. |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2029 | NearLabel done_label; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2030 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2031 | // False case: result = 0. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2032 | __ Bind(&false_label); |
| 2033 | __ xorl(reg, reg); |
| 2034 | __ jmp(&done_label); |
| 2035 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2036 | // True case: result = 1. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2037 | __ Bind(&true_label); |
| 2038 | __ movl(reg, Immediate(1)); |
| 2039 | __ Bind(&done_label); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2040 | } |
| 2041 | |
| 2042 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2043 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2047 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2048 | } |
| 2049 | |
| 2050 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2051 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2052 | } |
| 2053 | |
| 2054 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2055 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2056 | } |
| 2057 | |
| 2058 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2059 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2063 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2067 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2068 | } |
| 2069 | |
| 2070 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2071 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2072 | } |
| 2073 | |
| 2074 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2075 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2076 | } |
| 2077 | |
| 2078 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2079 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2083 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2084 | } |
| 2085 | |
| 2086 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2087 | HandleCondition(comp); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2088 | } |
| 2089 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2090 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2091 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2095 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2096 | } |
| 2097 | |
| 2098 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2099 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2100 | } |
| 2101 | |
| 2102 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2103 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2104 | } |
| 2105 | |
| 2106 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2107 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2108 | } |
| 2109 | |
| 2110 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2111 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2112 | } |
| 2113 | |
| 2114 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2115 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2116 | } |
| 2117 | |
| 2118 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2119 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2120 | } |
| 2121 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2122 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2123 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2124 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2125 | switch (compare->InputAt(0)->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2126 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2127 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2128 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2129 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2130 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2131 | case DataType::Type::kInt32: |
| 2132 | case DataType::Type::kInt64: { |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2133 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2134 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2135 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2136 | break; |
| 2137 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2138 | case DataType::Type::kFloat32: |
| 2139 | case DataType::Type::kFloat64: { |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2140 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2141 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2142 | locations->SetOut(Location::RequiresRegister()); |
| 2143 | break; |
| 2144 | } |
| 2145 | default: |
| 2146 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 2147 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2151 | LocationSummary* locations = compare->GetLocations(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2152 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2153 | Location left = locations->InAt(0); |
| 2154 | Location right = locations->InAt(1); |
| 2155 | |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2156 | NearLabel less, greater, done; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2157 | DataType::Type type = compare->InputAt(0)->GetType(); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2158 | Condition less_cond = kLess; |
| 2159 | |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2160 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2161 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2162 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2163 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2164 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2165 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2166 | case DataType::Type::kInt32: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2167 | codegen_->GenerateIntCompare(left, right); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2168 | break; |
| 2169 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2170 | case DataType::Type::kInt64: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2171 | codegen_->GenerateLongCompare(left, right); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2172 | break; |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2173 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2174 | case DataType::Type::kFloat32: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2175 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2176 | if (right.IsConstant()) { |
| 2177 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 2178 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 2179 | } else if (right.IsStackSlot()) { |
| 2180 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2181 | } else { |
| 2182 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2183 | } |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2184 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2185 | less_cond = kBelow; // ucomis{s,d} sets CF |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2186 | break; |
| 2187 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2188 | case DataType::Type::kFloat64: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2189 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2190 | if (right.IsConstant()) { |
| 2191 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2192 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 2193 | } else if (right.IsDoubleStackSlot()) { |
| 2194 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2195 | } else { |
| 2196 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2197 | } |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2198 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2199 | less_cond = kBelow; // ucomis{s,d} sets CF |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2200 | break; |
| 2201 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2202 | default: |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2203 | LOG(FATAL) << "Unexpected compare type " << type; |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2204 | } |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2205 | |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2206 | __ movl(out, Immediate(0)); |
| Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2207 | __ j(kEqual, &done); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2208 | __ j(less_cond, &less); |
| Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2209 | |
| Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2210 | __ Bind(&greater); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2211 | __ movl(out, Immediate(1)); |
| 2212 | __ jmp(&done); |
| 2213 | |
| 2214 | __ Bind(&less); |
| 2215 | __ movl(out, Immediate(-1)); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2216 | |
| 2217 | __ Bind(&done); |
| 2218 | } |
| 2219 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2220 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2221 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2222 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2223 | locations->SetOut(Location::ConstantLocation(constant)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2224 | } |
| 2225 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2226 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2227 | // Will be generated at use site. |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2228 | } |
| 2229 | |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2230 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 2231 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2232 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2233 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2234 | } |
| 2235 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2236 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2237 | // Will be generated at use site. |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2238 | } |
| 2239 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2240 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2241 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2242 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2243 | locations->SetOut(Location::ConstantLocation(constant)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2244 | } |
| 2245 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2246 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2247 | // Will be generated at use site. |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2248 | } |
| 2249 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2250 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 2251 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2252 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2253 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2254 | } |
| 2255 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2256 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2257 | // Will be generated at use site. |
| 2258 | } |
| 2259 | |
| 2260 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2261 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2262 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2263 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2264 | } |
| 2265 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2266 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 2267 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2268 | // Will be generated at use site. |
| 2269 | } |
| 2270 | |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2271 | void LocationsBuilderX86_64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2272 | constructor_fence->SetLocations(nullptr); |
| 2273 | } |
| 2274 | |
| 2275 | void InstructionCodeGeneratorX86_64::VisitConstructorFence( |
| 2276 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2277 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2278 | } |
| 2279 | |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2280 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2281 | memory_barrier->SetLocations(nullptr); |
| 2282 | } |
| 2283 | |
| 2284 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2285 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2286 | } |
| 2287 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2288 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 2289 | ret->SetLocations(nullptr); |
| 2290 | } |
| 2291 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2292 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2293 | codegen_->GenerateFrameExit(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2294 | } |
| 2295 | |
| 2296 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2297 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2298 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2299 | switch (ret->InputAt(0)->GetType()) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2300 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2301 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2302 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2303 | case DataType::Type::kInt8: |
| 2304 | case DataType::Type::kUint16: |
| 2305 | case DataType::Type::kInt16: |
| 2306 | case DataType::Type::kInt32: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2307 | case DataType::Type::kInt64: |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2308 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2309 | break; |
| 2310 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2311 | case DataType::Type::kFloat32: |
| 2312 | case DataType::Type::kFloat64: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2313 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2314 | break; |
| 2315 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2316 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2317 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2318 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2319 | } |
| 2320 | |
| 2321 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 2322 | if (kIsDebugBuild) { |
| 2323 | switch (ret->InputAt(0)->GetType()) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2324 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2325 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2326 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2327 | case DataType::Type::kInt8: |
| 2328 | case DataType::Type::kUint16: |
| 2329 | case DataType::Type::kInt16: |
| 2330 | case DataType::Type::kInt32: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2331 | case DataType::Type::kInt64: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2332 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2333 | break; |
| 2334 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2335 | case DataType::Type::kFloat32: |
| 2336 | case DataType::Type::kFloat64: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2337 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2338 | XMM0); |
| 2339 | break; |
| 2340 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2341 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2342 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2343 | } |
| 2344 | } |
| 2345 | codegen_->GenerateFrameExit(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2346 | } |
| 2347 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2348 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(DataType::Type type) const { |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2349 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2350 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2351 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2352 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2353 | case DataType::Type::kInt8: |
| 2354 | case DataType::Type::kUint16: |
| 2355 | case DataType::Type::kInt16: |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2356 | case DataType::Type::kUint32: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2357 | case DataType::Type::kInt32: |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2358 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2359 | case DataType::Type::kInt64: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2360 | return Location::RegisterLocation(RAX); |
| 2361 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2362 | case DataType::Type::kVoid: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2363 | return Location::NoLocation(); |
| 2364 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2365 | case DataType::Type::kFloat64: |
| 2366 | case DataType::Type::kFloat32: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2367 | return Location::FpuRegisterLocation(XMM0); |
| 2368 | } |
| Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2369 | |
| 2370 | UNREACHABLE(); |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2374 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2375 | } |
| 2376 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2377 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(DataType::Type type) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2378 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2379 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2380 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2381 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2382 | case DataType::Type::kInt8: |
| 2383 | case DataType::Type::kUint16: |
| 2384 | case DataType::Type::kInt16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2385 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2386 | uint32_t index = gp_index_++; |
| 2387 | stack_index_++; |
| 2388 | if (index < calling_convention.GetNumberOfRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2389 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2390 | } else { |
| 2391 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2392 | } |
| 2393 | } |
| 2394 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2395 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2396 | uint32_t index = gp_index_; |
| 2397 | stack_index_ += 2; |
| 2398 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2399 | gp_index_ += 1; |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2400 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2401 | } else { |
| 2402 | gp_index_ += 2; |
| 2403 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2404 | } |
| 2405 | } |
| 2406 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2407 | case DataType::Type::kFloat32: { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2408 | uint32_t index = float_index_++; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2409 | stack_index_++; |
| 2410 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2411 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2412 | } else { |
| 2413 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2414 | } |
| 2415 | } |
| 2416 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2417 | case DataType::Type::kFloat64: { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2418 | uint32_t index = float_index_++; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2419 | stack_index_ += 2; |
| 2420 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2421 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2422 | } else { |
| 2423 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2424 | } |
| 2425 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2426 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2427 | case DataType::Type::kUint32: |
| 2428 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2429 | case DataType::Type::kVoid: |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2430 | LOG(FATAL) << "Unexpected parameter type " << type; |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 2431 | UNREACHABLE(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2432 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2433 | return Location::NoLocation(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2434 | } |
| 2435 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2436 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2437 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2438 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2439 | // the method_idx. |
| 2440 | HandleInvoke(invoke); |
| 2441 | } |
| 2442 | |
| 2443 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2444 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2445 | } |
| 2446 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2447 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2448 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2449 | // art::PrepareForRegisterAllocation. |
| 2450 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2451 | |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2452 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2453 | if (intrinsic.TryDispatch(invoke)) { |
| 2454 | return; |
| 2455 | } |
| 2456 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2457 | HandleInvoke(invoke); |
| 2458 | } |
| 2459 | |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2460 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2461 | if (invoke->GetLocations()->Intrinsified()) { |
| 2462 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2463 | intrinsic.Dispatch(invoke); |
| 2464 | return true; |
| 2465 | } |
| 2466 | return false; |
| 2467 | } |
| 2468 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2469 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2470 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2471 | // art::PrepareForRegisterAllocation. |
| 2472 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2473 | |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2474 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2475 | return; |
| 2476 | } |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2477 | |
| Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2478 | LocationSummary* locations = invoke->GetLocations(); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2479 | codegen_->GenerateStaticOrDirectCall( |
| Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2480 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2481 | } |
| 2482 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2483 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2484 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2485 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2486 | } |
| 2487 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2488 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2489 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2490 | if (intrinsic.TryDispatch(invoke)) { |
| 2491 | return; |
| 2492 | } |
| 2493 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2494 | HandleInvoke(invoke); |
| 2495 | } |
| 2496 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2497 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2498 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2499 | return; |
| 2500 | } |
| 2501 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2502 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2503 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2504 | } |
| 2505 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2506 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2507 | HandleInvoke(invoke); |
| 2508 | // Add the hidden argument. |
| 2509 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2510 | } |
| 2511 | |
| 2512 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2513 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2514 | LocationSummary* locations = invoke->GetLocations(); |
| 2515 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2516 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2517 | Location receiver = locations->InAt(0); |
| 2518 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2519 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2520 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2521 | // won't be modified thereafter, before the `call` instruction. |
| 2522 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2523 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2524 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2525 | if (receiver.IsStackSlot()) { |
| 2526 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2527 | // /* HeapReference<Class> */ temp = temp->klass_ |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2528 | __ movl(temp, Address(temp, class_offset)); |
| 2529 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2530 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2531 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2532 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2533 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2534 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2535 | // emit a read barrier for the previous class reference load. |
| 2536 | // However this is not required in practice, as this is an |
| 2537 | // intermediate/temporary reference and because the current |
| 2538 | // concurrent copying collector keeps the from-space memory |
| 2539 | // intact/accessible until the end of the marking phase (the |
| 2540 | // concurrent copying collector may not in the future). |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2541 | __ MaybeUnpoisonHeapReference(temp); |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2542 | // temp = temp->GetAddressOfIMT() |
| 2543 | __ movq(temp, |
| 2544 | Address(temp, mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| 2545 | // temp = temp->GetImtEntryAt(method_offset); |
| 2546 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2547 | invoke->GetImtIndex(), kX86_64PointerSize)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2548 | // temp = temp->GetImtEntryAt(method_offset); |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2549 | __ movq(temp, Address(temp, method_offset)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2550 | // call temp->GetEntryPoint(); |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2551 | __ call(Address( |
| 2552 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize).SizeValue())); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2553 | |
| 2554 | DCHECK(!codegen_->IsLeafMethod()); |
| 2555 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2556 | } |
| 2557 | |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2558 | void LocationsBuilderX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2559 | HandleInvoke(invoke); |
| 2560 | } |
| 2561 | |
| 2562 | void InstructionCodeGeneratorX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2563 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2564 | } |
| 2565 | |
| Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 2566 | void LocationsBuilderX86_64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2567 | HandleInvoke(invoke); |
| 2568 | } |
| 2569 | |
| 2570 | void InstructionCodeGeneratorX86_64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2571 | codegen_->GenerateInvokeCustomCall(invoke); |
| 2572 | } |
| 2573 | |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2574 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2575 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2576 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2577 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2578 | case DataType::Type::kInt32: |
| 2579 | case DataType::Type::kInt64: |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2580 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2581 | locations->SetOut(Location::SameAsFirstInput()); |
| 2582 | break; |
| 2583 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2584 | case DataType::Type::kFloat32: |
| 2585 | case DataType::Type::kFloat64: |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2586 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2587 | locations->SetOut(Location::SameAsFirstInput()); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2588 | locations->AddTemp(Location::RequiresFpuRegister()); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2589 | break; |
| 2590 | |
| 2591 | default: |
| 2592 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2593 | } |
| 2594 | } |
| 2595 | |
| 2596 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2597 | LocationSummary* locations = neg->GetLocations(); |
| 2598 | Location out = locations->Out(); |
| 2599 | Location in = locations->InAt(0); |
| 2600 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2601 | case DataType::Type::kInt32: |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2602 | DCHECK(in.IsRegister()); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2603 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2604 | __ negl(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2605 | break; |
| 2606 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2607 | case DataType::Type::kInt64: |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2608 | DCHECK(in.IsRegister()); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2609 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2610 | __ negq(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2611 | break; |
| 2612 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2613 | case DataType::Type::kFloat32: { |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2614 | DCHECK(in.Equals(out)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2615 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2616 | // Implement float negation with an exclusive or with value |
| 2617 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2618 | // single-precision floating-point number). |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2619 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2620 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2621 | break; |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2622 | } |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2623 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2624 | case DataType::Type::kFloat64: { |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2625 | DCHECK(in.Equals(out)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2626 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2627 | // Implement double negation with an exclusive or with value |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2628 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2629 | // a double-precision floating-point number). |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2630 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2631 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2632 | break; |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2633 | } |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2634 | |
| 2635 | default: |
| 2636 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2637 | } |
| 2638 | } |
| 2639 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2640 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2641 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2642 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2643 | DataType::Type result_type = conversion->GetResultType(); |
| 2644 | DataType::Type input_type = conversion->GetInputType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2645 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2646 | << input_type << " -> " << result_type; |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2647 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2648 | switch (result_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2649 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2650 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2651 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2652 | case DataType::Type::kInt16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2653 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2654 | locations->SetInAt(0, Location::Any()); |
| 2655 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2656 | break; |
| 2657 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2658 | case DataType::Type::kInt32: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2659 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2660 | case DataType::Type::kInt64: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2661 | locations->SetInAt(0, Location::Any()); |
| 2662 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2663 | break; |
| 2664 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2665 | case DataType::Type::kFloat32: |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2666 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2667 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2668 | break; |
| 2669 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2670 | case DataType::Type::kFloat64: |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2671 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2672 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2673 | break; |
| 2674 | |
| 2675 | default: |
| 2676 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2677 | << " to " << result_type; |
| 2678 | } |
| 2679 | break; |
| 2680 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2681 | case DataType::Type::kInt64: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2682 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2683 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2684 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2685 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2686 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2687 | case DataType::Type::kInt16: |
| 2688 | case DataType::Type::kInt32: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2689 | // TODO: We would benefit from a (to-be-implemented) |
| 2690 | // Location::RegisterOrStackSlot requirement for this input. |
| 2691 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2692 | locations->SetOut(Location::RequiresRegister()); |
| 2693 | break; |
| 2694 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2695 | case DataType::Type::kFloat32: |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2696 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2697 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2698 | break; |
| 2699 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2700 | case DataType::Type::kFloat64: |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2701 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2702 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2703 | break; |
| 2704 | |
| 2705 | default: |
| 2706 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2707 | << " to " << result_type; |
| 2708 | } |
| 2709 | break; |
| 2710 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2711 | case DataType::Type::kFloat32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2712 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2713 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2714 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2715 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2716 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2717 | case DataType::Type::kInt16: |
| 2718 | case DataType::Type::kInt32: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2719 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2720 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2721 | break; |
| 2722 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2723 | case DataType::Type::kInt64: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2724 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2725 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2726 | break; |
| 2727 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2728 | case DataType::Type::kFloat64: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2729 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2730 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2731 | break; |
| 2732 | |
| 2733 | default: |
| 2734 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2735 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2736 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2737 | break; |
| 2738 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2739 | case DataType::Type::kFloat64: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2740 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2741 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2742 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2743 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2744 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2745 | case DataType::Type::kInt16: |
| 2746 | case DataType::Type::kInt32: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2747 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2748 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2749 | break; |
| 2750 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2751 | case DataType::Type::kInt64: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2752 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2753 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2754 | break; |
| 2755 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2756 | case DataType::Type::kFloat32: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2757 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2758 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2759 | break; |
| 2760 | |
| 2761 | default: |
| 2762 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2763 | << " to " << result_type; |
| 2764 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2765 | break; |
| 2766 | |
| 2767 | default: |
| 2768 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2769 | << " to " << result_type; |
| 2770 | } |
| 2771 | } |
| 2772 | |
| 2773 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2774 | LocationSummary* locations = conversion->GetLocations(); |
| 2775 | Location out = locations->Out(); |
| 2776 | Location in = locations->InAt(0); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2777 | DataType::Type result_type = conversion->GetResultType(); |
| 2778 | DataType::Type input_type = conversion->GetInputType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2779 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2780 | << input_type << " -> " << result_type; |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2781 | switch (result_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2782 | case DataType::Type::kUint8: |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2783 | switch (input_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2784 | case DataType::Type::kInt8: |
| 2785 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2786 | case DataType::Type::kInt16: |
| 2787 | case DataType::Type::kInt32: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2788 | case DataType::Type::kInt64: |
| 2789 | if (in.IsRegister()) { |
| 2790 | __ movzxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| 2791 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| 2792 | __ movzxb(out.AsRegister<CpuRegister>(), |
| 2793 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2794 | } else { |
| 2795 | __ movl(out.AsRegister<CpuRegister>(), |
| 2796 | Immediate(static_cast<uint8_t>(Int64FromConstant(in.GetConstant())))); |
| 2797 | } |
| 2798 | break; |
| 2799 | |
| 2800 | default: |
| 2801 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2802 | << " to " << result_type; |
| 2803 | } |
| 2804 | break; |
| 2805 | |
| 2806 | case DataType::Type::kInt8: |
| 2807 | switch (input_type) { |
| 2808 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2809 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2810 | case DataType::Type::kInt16: |
| 2811 | case DataType::Type::kInt32: |
| 2812 | case DataType::Type::kInt64: |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2813 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2814 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2815 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2816 | __ movsxb(out.AsRegister<CpuRegister>(), |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2817 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2818 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2819 | __ movl(out.AsRegister<CpuRegister>(), |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2820 | Immediate(static_cast<int8_t>(Int64FromConstant(in.GetConstant())))); |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2821 | } |
| 2822 | break; |
| 2823 | |
| 2824 | default: |
| 2825 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2826 | << " to " << result_type; |
| 2827 | } |
| 2828 | break; |
| 2829 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2830 | case DataType::Type::kUint16: |
| 2831 | switch (input_type) { |
| 2832 | case DataType::Type::kInt8: |
| 2833 | case DataType::Type::kInt16: |
| 2834 | case DataType::Type::kInt32: |
| 2835 | case DataType::Type::kInt64: |
| 2836 | if (in.IsRegister()) { |
| 2837 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| 2838 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| 2839 | __ movzxw(out.AsRegister<CpuRegister>(), |
| 2840 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2841 | } else { |
| 2842 | __ movl(out.AsRegister<CpuRegister>(), |
| 2843 | Immediate(static_cast<uint16_t>(Int64FromConstant(in.GetConstant())))); |
| 2844 | } |
| 2845 | break; |
| 2846 | |
| 2847 | default: |
| 2848 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2849 | << " to " << result_type; |
| 2850 | } |
| 2851 | break; |
| 2852 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2853 | case DataType::Type::kInt16: |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2854 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2855 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2856 | case DataType::Type::kInt32: |
| 2857 | case DataType::Type::kInt64: |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2858 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2859 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2860 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2861 | __ movsxw(out.AsRegister<CpuRegister>(), |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2862 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2863 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2864 | __ movl(out.AsRegister<CpuRegister>(), |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2865 | Immediate(static_cast<int16_t>(Int64FromConstant(in.GetConstant())))); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2866 | } |
| 2867 | break; |
| 2868 | |
| 2869 | default: |
| 2870 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2871 | << " to " << result_type; |
| 2872 | } |
| 2873 | break; |
| 2874 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2875 | case DataType::Type::kInt32: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2876 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2877 | case DataType::Type::kInt64: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2878 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2879 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2880 | } else if (in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2881 | __ movl(out.AsRegister<CpuRegister>(), |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2882 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2883 | } else { |
| 2884 | DCHECK(in.IsConstant()); |
| 2885 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2886 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2887 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2888 | } |
| 2889 | break; |
| 2890 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2891 | case DataType::Type::kFloat32: { |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2892 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2893 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2894 | NearLabel done, nan; |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2895 | |
| 2896 | __ movl(output, Immediate(kPrimIntMax)); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2897 | // if input >= (float)INT_MAX goto done |
| 2898 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2899 | __ j(kAboveEqual, &done); |
| 2900 | // if input == NaN goto nan |
| 2901 | __ j(kUnordered, &nan); |
| 2902 | // output = float-to-int-truncate(input) |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2903 | __ cvttss2si(output, input, false); |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2904 | __ jmp(&done); |
| 2905 | __ Bind(&nan); |
| 2906 | // output = 0 |
| 2907 | __ xorl(output, output); |
| 2908 | __ Bind(&done); |
| 2909 | break; |
| 2910 | } |
| 2911 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2912 | case DataType::Type::kFloat64: { |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2913 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2914 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2915 | NearLabel done, nan; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2916 | |
| 2917 | __ movl(output, Immediate(kPrimIntMax)); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2918 | // if input >= (double)INT_MAX goto done |
| 2919 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2920 | __ j(kAboveEqual, &done); |
| 2921 | // if input == NaN goto nan |
| 2922 | __ j(kUnordered, &nan); |
| 2923 | // output = double-to-int-truncate(input) |
| 2924 | __ cvttsd2si(output, input); |
| 2925 | __ jmp(&done); |
| 2926 | __ Bind(&nan); |
| 2927 | // output = 0 |
| 2928 | __ xorl(output, output); |
| 2929 | __ Bind(&done); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2930 | break; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2931 | } |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2932 | |
| 2933 | default: |
| 2934 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2935 | << " to " << result_type; |
| 2936 | } |
| 2937 | break; |
| 2938 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2939 | case DataType::Type::kInt64: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2940 | switch (input_type) { |
| 2941 | DCHECK(out.IsRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2942 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2943 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2944 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2945 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2946 | case DataType::Type::kInt16: |
| 2947 | case DataType::Type::kInt32: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2948 | DCHECK(in.IsRegister()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2949 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2950 | break; |
| 2951 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2952 | case DataType::Type::kFloat32: { |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2953 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2954 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2955 | NearLabel done, nan; |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2956 | |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2957 | codegen_->Load64BitValue(output, kPrimLongMax); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2958 | // if input >= (float)LONG_MAX goto done |
| 2959 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2960 | __ j(kAboveEqual, &done); |
| 2961 | // if input == NaN goto nan |
| 2962 | __ j(kUnordered, &nan); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2963 | // output = float-to-long-truncate(input) |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2964 | __ cvttss2si(output, input, true); |
| 2965 | __ jmp(&done); |
| 2966 | __ Bind(&nan); |
| 2967 | // output = 0 |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2968 | __ xorl(output, output); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2969 | __ Bind(&done); |
| 2970 | break; |
| 2971 | } |
| 2972 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2973 | case DataType::Type::kFloat64: { |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2974 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2975 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2976 | NearLabel done, nan; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2977 | |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2978 | codegen_->Load64BitValue(output, kPrimLongMax); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2979 | // if input >= (double)LONG_MAX goto done |
| 2980 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2981 | __ j(kAboveEqual, &done); |
| 2982 | // if input == NaN goto nan |
| 2983 | __ j(kUnordered, &nan); |
| 2984 | // output = double-to-long-truncate(input) |
| 2985 | __ cvttsd2si(output, input, true); |
| 2986 | __ jmp(&done); |
| 2987 | __ Bind(&nan); |
| 2988 | // output = 0 |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2989 | __ xorl(output, output); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2990 | __ Bind(&done); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2991 | break; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2992 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2993 | |
| 2994 | default: |
| 2995 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2996 | << " to " << result_type; |
| 2997 | } |
| 2998 | break; |
| 2999 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3000 | case DataType::Type::kFloat32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3001 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3002 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3003 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3004 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3005 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3006 | case DataType::Type::kInt16: |
| 3007 | case DataType::Type::kInt32: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3008 | if (in.IsRegister()) { |
| 3009 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 3010 | } else if (in.IsConstant()) { |
| 3011 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3012 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3013 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3014 | } else { |
| 3015 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 3016 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 3017 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3018 | break; |
| 3019 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3020 | case DataType::Type::kInt64: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3021 | if (in.IsRegister()) { |
| 3022 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 3023 | } else if (in.IsConstant()) { |
| 3024 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3025 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 3026 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3027 | } else { |
| 3028 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 3029 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 3030 | } |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3031 | break; |
| 3032 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3033 | case DataType::Type::kFloat64: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3034 | if (in.IsFpuRegister()) { |
| 3035 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 3036 | } else if (in.IsConstant()) { |
| 3037 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 3038 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3039 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3040 | } else { |
| 3041 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 3042 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3043 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3044 | break; |
| 3045 | |
| 3046 | default: |
| 3047 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3048 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3049 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3050 | break; |
| 3051 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3052 | case DataType::Type::kFloat64: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3053 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3054 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3055 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3056 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3057 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3058 | case DataType::Type::kInt16: |
| 3059 | case DataType::Type::kInt32: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3060 | if (in.IsRegister()) { |
| 3061 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 3062 | } else if (in.IsConstant()) { |
| 3063 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3064 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3065 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3066 | } else { |
| 3067 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3068 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 3069 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3070 | break; |
| 3071 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3072 | case DataType::Type::kInt64: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3073 | if (in.IsRegister()) { |
| 3074 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 3075 | } else if (in.IsConstant()) { |
| 3076 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3077 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3078 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3079 | } else { |
| 3080 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3081 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 3082 | } |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3083 | break; |
| 3084 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3085 | case DataType::Type::kFloat32: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3086 | if (in.IsFpuRegister()) { |
| 3087 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 3088 | } else if (in.IsConstant()) { |
| 3089 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 3090 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3091 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3092 | } else { |
| 3093 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 3094 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3095 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3096 | break; |
| 3097 | |
| 3098 | default: |
| 3099 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3100 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3101 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3102 | break; |
| 3103 | |
| 3104 | default: |
| 3105 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3106 | << " to " << result_type; |
| 3107 | } |
| 3108 | } |
| 3109 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3110 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3111 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3112 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3113 | switch (add->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3114 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3115 | locations->SetInAt(0, Location::RequiresRegister()); |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3116 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3117 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3118 | break; |
| 3119 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3120 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3121 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3122 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3123 | // We can use a leaq or addq if the constant can fit in an immediate. |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 3124 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3125 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3126 | break; |
| 3127 | } |
| 3128 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3129 | case DataType::Type::kFloat64: |
| 3130 | case DataType::Type::kFloat32: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3131 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3132 | locations->SetInAt(1, Location::Any()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3133 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3134 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3135 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3136 | |
| 3137 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3138 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3139 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3140 | } |
| 3141 | |
| 3142 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 3143 | LocationSummary* locations = add->GetLocations(); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3144 | Location first = locations->InAt(0); |
| 3145 | Location second = locations->InAt(1); |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3146 | Location out = locations->Out(); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3147 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3148 | switch (add->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3149 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3150 | if (second.IsRegister()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3151 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3152 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3153 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3154 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3155 | } else { |
| 3156 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3157 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3158 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3159 | } else if (second.IsConstant()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3160 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3161 | __ addl(out.AsRegister<CpuRegister>(), |
| 3162 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 3163 | } else { |
| 3164 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3165 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 3166 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3167 | } else { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3168 | DCHECK(first.Equals(locations->Out())); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3169 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3170 | } |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3171 | break; |
| 3172 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3173 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3174 | case DataType::Type::kInt64: { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3175 | if (second.IsRegister()) { |
| 3176 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3177 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3178 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3179 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3180 | } else { |
| 3181 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3182 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3183 | } |
| 3184 | } else { |
| 3185 | DCHECK(second.IsConstant()); |
| 3186 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3187 | int32_t int32_value = Low32Bits(value); |
| 3188 | DCHECK_EQ(int32_value, value); |
| 3189 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3190 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 3191 | } else { |
| 3192 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3193 | first.AsRegister<CpuRegister>(), int32_value)); |
| 3194 | } |
| 3195 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3196 | break; |
| 3197 | } |
| 3198 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3199 | case DataType::Type::kFloat32: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3200 | if (second.IsFpuRegister()) { |
| 3201 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3202 | } else if (second.IsConstant()) { |
| 3203 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3204 | codegen_->LiteralFloatAddress( |
| 3205 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3206 | } else { |
| 3207 | DCHECK(second.IsStackSlot()); |
| 3208 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3209 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3210 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3211 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3212 | } |
| 3213 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3214 | case DataType::Type::kFloat64: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3215 | if (second.IsFpuRegister()) { |
| 3216 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3217 | } else if (second.IsConstant()) { |
| 3218 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3219 | codegen_->LiteralDoubleAddress( |
| 3220 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3221 | } else { |
| 3222 | DCHECK(second.IsDoubleStackSlot()); |
| 3223 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3224 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3225 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3226 | break; |
| 3227 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3228 | |
| 3229 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3230 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3231 | } |
| 3232 | } |
| 3233 | |
| 3234 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3235 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3236 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3237 | switch (sub->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3238 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3239 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3240 | locations->SetInAt(1, Location::Any()); |
| 3241 | locations->SetOut(Location::SameAsFirstInput()); |
| 3242 | break; |
| 3243 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3244 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3245 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 3246 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3247 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3248 | break; |
| 3249 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3250 | case DataType::Type::kFloat32: |
| 3251 | case DataType::Type::kFloat64: { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3252 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3253 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3254 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3255 | break; |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3256 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3257 | default: |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3258 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3259 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3260 | } |
| 3261 | |
| 3262 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 3263 | LocationSummary* locations = sub->GetLocations(); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3264 | Location first = locations->InAt(0); |
| 3265 | Location second = locations->InAt(1); |
| 3266 | DCHECK(first.Equals(locations->Out())); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3267 | switch (sub->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3268 | case DataType::Type::kInt32: { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3269 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3270 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3271 | } else if (second.IsConstant()) { |
| 3272 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3273 | __ subl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3274 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3275 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3276 | } |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3277 | break; |
| 3278 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3279 | case DataType::Type::kInt64: { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3280 | if (second.IsConstant()) { |
| 3281 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3282 | DCHECK(IsInt<32>(value)); |
| 3283 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 3284 | } else { |
| 3285 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 3286 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3287 | break; |
| 3288 | } |
| 3289 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3290 | case DataType::Type::kFloat32: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3291 | if (second.IsFpuRegister()) { |
| 3292 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3293 | } else if (second.IsConstant()) { |
| 3294 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3295 | codegen_->LiteralFloatAddress( |
| 3296 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3297 | } else { |
| 3298 | DCHECK(second.IsStackSlot()); |
| 3299 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3300 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3301 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3302 | break; |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3303 | } |
| 3304 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3305 | case DataType::Type::kFloat64: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3306 | if (second.IsFpuRegister()) { |
| 3307 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3308 | } else if (second.IsConstant()) { |
| 3309 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3310 | codegen_->LiteralDoubleAddress( |
| 3311 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3312 | } else { |
| 3313 | DCHECK(second.IsDoubleStackSlot()); |
| 3314 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3315 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3316 | } |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3317 | break; |
| 3318 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3319 | |
| 3320 | default: |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3321 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3322 | } |
| 3323 | } |
| 3324 | |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3325 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3326 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3327 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3328 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3329 | case DataType::Type::kInt32: { |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3330 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3331 | locations->SetInAt(1, Location::Any()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3332 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3333 | // Can use 3 operand multiply. |
| 3334 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3335 | } else { |
| 3336 | locations->SetOut(Location::SameAsFirstInput()); |
| 3337 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3338 | break; |
| 3339 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3340 | case DataType::Type::kInt64: { |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3341 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3342 | locations->SetInAt(1, Location::Any()); |
| 3343 | if (mul->InputAt(1)->IsLongConstant() && |
| 3344 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3345 | // Can use 3 operand multiply. |
| 3346 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3347 | } else { |
| 3348 | locations->SetOut(Location::SameAsFirstInput()); |
| 3349 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3350 | break; |
| 3351 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3352 | case DataType::Type::kFloat32: |
| 3353 | case DataType::Type::kFloat64: { |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3354 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3355 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3356 | locations->SetOut(Location::SameAsFirstInput()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3357 | break; |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3358 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3359 | |
| 3360 | default: |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3361 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3362 | } |
| 3363 | } |
| 3364 | |
| 3365 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3366 | LocationSummary* locations = mul->GetLocations(); |
| 3367 | Location first = locations->InAt(0); |
| 3368 | Location second = locations->InAt(1); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3369 | Location out = locations->Out(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3370 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3371 | case DataType::Type::kInt32: |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3372 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3373 | // problems where the output may not be the same as the first operand. |
| 3374 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3375 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3376 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3377 | } else if (second.IsRegister()) { |
| 3378 | DCHECK(first.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3379 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3380 | } else { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3381 | DCHECK(first.Equals(out)); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3382 | DCHECK(second.IsStackSlot()); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3383 | __ imull(first.AsRegister<CpuRegister>(), |
| 3384 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3385 | } |
| 3386 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3387 | case DataType::Type::kInt64: { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3388 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3389 | // problems where the output may not be the same as the first operand. |
| 3390 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3391 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3392 | if (IsInt<32>(value)) { |
| 3393 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3394 | Immediate(static_cast<int32_t>(value))); |
| 3395 | } else { |
| 3396 | // Have to use the constant area. |
| 3397 | DCHECK(first.Equals(out)); |
| 3398 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3399 | } |
| 3400 | } else if (second.IsRegister()) { |
| 3401 | DCHECK(first.Equals(out)); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3402 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3403 | } else { |
| 3404 | DCHECK(second.IsDoubleStackSlot()); |
| 3405 | DCHECK(first.Equals(out)); |
| 3406 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3407 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3408 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3409 | break; |
| 3410 | } |
| 3411 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3412 | case DataType::Type::kFloat32: { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3413 | DCHECK(first.Equals(out)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3414 | if (second.IsFpuRegister()) { |
| 3415 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3416 | } else if (second.IsConstant()) { |
| 3417 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3418 | codegen_->LiteralFloatAddress( |
| 3419 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3420 | } else { |
| 3421 | DCHECK(second.IsStackSlot()); |
| 3422 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3423 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3424 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3425 | break; |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3426 | } |
| 3427 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3428 | case DataType::Type::kFloat64: { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3429 | DCHECK(first.Equals(out)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3430 | if (second.IsFpuRegister()) { |
| 3431 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3432 | } else if (second.IsConstant()) { |
| 3433 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3434 | codegen_->LiteralDoubleAddress( |
| 3435 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3436 | } else { |
| 3437 | DCHECK(second.IsDoubleStackSlot()); |
| 3438 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3439 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3440 | } |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3441 | break; |
| 3442 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3443 | |
| 3444 | default: |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3445 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3446 | } |
| 3447 | } |
| 3448 | |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3449 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3450 | uint32_t stack_adjustment, bool is_float) { |
| 3451 | if (source.IsStackSlot()) { |
| 3452 | DCHECK(is_float); |
| 3453 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3454 | } else if (source.IsDoubleStackSlot()) { |
| 3455 | DCHECK(!is_float); |
| 3456 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3457 | } else { |
| 3458 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3459 | if (is_float) { |
| 3460 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3461 | codegen_->Move(stack_temp, source); |
| 3462 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3463 | } else { |
| 3464 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3465 | codegen_->Move(stack_temp, source); |
| 3466 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3467 | } |
| 3468 | } |
| 3469 | } |
| 3470 | |
| 3471 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3472 | DataType::Type type = rem->GetResultType(); |
| 3473 | bool is_float = type == DataType::Type::kFloat32; |
| 3474 | size_t elem_size = DataType::Size(type); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3475 | LocationSummary* locations = rem->GetLocations(); |
| 3476 | Location first = locations->InAt(0); |
| 3477 | Location second = locations->InAt(1); |
| 3478 | Location out = locations->Out(); |
| 3479 | |
| 3480 | // Create stack space for 2 elements. |
| 3481 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3482 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3483 | |
| 3484 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3485 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3486 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3487 | |
| 3488 | // Loop doing FPREM until we stabilize. |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3489 | NearLabel retry; |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3490 | __ Bind(&retry); |
| 3491 | __ fprem(); |
| 3492 | |
| 3493 | // Move FP status to AX. |
| 3494 | __ fstsw(); |
| 3495 | |
| 3496 | // And see if the argument reduction is complete. This is signaled by the |
| 3497 | // C2 FPU flag bit set to 0. |
| 3498 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3499 | __ j(kNotEqual, &retry); |
| 3500 | |
| 3501 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3502 | // Store FP top of stack to real stack. |
| 3503 | if (is_float) { |
| 3504 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3505 | } else { |
| 3506 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3507 | } |
| 3508 | |
| 3509 | // Pop the 2 items from the FP stack. |
| 3510 | __ fucompp(); |
| 3511 | |
| 3512 | // Load the value from the stack into an XMM register. |
| 3513 | DCHECK(out.IsFpuRegister()) << out; |
| 3514 | if (is_float) { |
| 3515 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3516 | } else { |
| 3517 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3518 | } |
| 3519 | |
| 3520 | // And remove the temporary stack space we allocated. |
| 3521 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3522 | } |
| 3523 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3524 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3525 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3526 | |
| 3527 | LocationSummary* locations = instruction->GetLocations(); |
| 3528 | Location second = locations->InAt(1); |
| 3529 | DCHECK(second.IsConstant()); |
| 3530 | |
| 3531 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3532 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3533 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3534 | |
| 3535 | DCHECK(imm == 1 || imm == -1); |
| 3536 | |
| 3537 | switch (instruction->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3538 | case DataType::Type::kInt32: { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3539 | if (instruction->IsRem()) { |
| 3540 | __ xorl(output_register, output_register); |
| 3541 | } else { |
| 3542 | __ movl(output_register, input_register); |
| 3543 | if (imm == -1) { |
| 3544 | __ negl(output_register); |
| 3545 | } |
| 3546 | } |
| 3547 | break; |
| 3548 | } |
| 3549 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3550 | case DataType::Type::kInt64: { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3551 | if (instruction->IsRem()) { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3552 | __ xorl(output_register, output_register); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3553 | } else { |
| 3554 | __ movq(output_register, input_register); |
| 3555 | if (imm == -1) { |
| 3556 | __ negq(output_register); |
| 3557 | } |
| 3558 | } |
| 3559 | break; |
| 3560 | } |
| 3561 | |
| 3562 | default: |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3563 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3564 | } |
| 3565 | } |
| Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3566 | void InstructionCodeGeneratorX86_64::RemByPowerOfTwo(HRem* instruction) { |
| 3567 | LocationSummary* locations = instruction->GetLocations(); |
| 3568 | Location second = locations->InAt(1); |
| 3569 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3570 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3571 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3572 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3573 | uint64_t abs_imm = AbsOrMin(imm); |
| 3574 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3575 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| 3576 | NearLabel done; |
| 3577 | __ movl(out, numerator); |
| 3578 | __ andl(out, Immediate(abs_imm-1)); |
| 3579 | __ j(Condition::kZero, &done); |
| 3580 | __ leal(tmp, Address(out, static_cast<int32_t>(~(abs_imm-1)))); |
| 3581 | __ testl(numerator, numerator); |
| 3582 | __ cmov(Condition::kLess, out, tmp, false); |
| 3583 | __ Bind(&done); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3584 | |
| Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3585 | } else { |
| 3586 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| 3587 | codegen_->Load64BitValue(tmp, abs_imm - 1); |
| 3588 | NearLabel done; |
| 3589 | |
| 3590 | __ movq(out, numerator); |
| 3591 | __ andq(out, tmp); |
| 3592 | __ j(Condition::kZero, &done); |
| 3593 | __ movq(tmp, numerator); |
| 3594 | __ sarq(tmp, Immediate(63)); |
| 3595 | __ shlq(tmp, Immediate(WhichPowerOf2(abs_imm))); |
| 3596 | __ orq(out, tmp); |
| 3597 | __ Bind(&done); |
| 3598 | } |
| 3599 | } |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3600 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3601 | LocationSummary* locations = instruction->GetLocations(); |
| 3602 | Location second = locations->InAt(1); |
| 3603 | |
| 3604 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3605 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3606 | |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3607 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3608 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3609 | uint64_t abs_imm = AbsOrMin(imm); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3610 | |
| 3611 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3612 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3613 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| Atul Bajaj | 1cc7329 | 2018-11-15 11:36:53 +0530 | [diff] [blame] | 3614 | // When denominator is equal to 2, we can add signed bit and numerator to tmp. |
| 3615 | // Below we are using addl instruction instead of cmov which give us 1 cycle benefit. |
| 3616 | if (abs_imm == 2) { |
| 3617 | __ leal(tmp, Address(numerator, 0)); |
| 3618 | __ shrl(tmp, Immediate(31)); |
| 3619 | __ addl(tmp, numerator); |
| 3620 | } else { |
| 3621 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
| 3622 | __ testl(numerator, numerator); |
| 3623 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3624 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3625 | int shift = CTZ(imm); |
| 3626 | __ sarl(tmp, Immediate(shift)); |
| 3627 | |
| 3628 | if (imm < 0) { |
| 3629 | __ negl(tmp); |
| 3630 | } |
| 3631 | |
| 3632 | __ movl(output_register, tmp); |
| 3633 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3634 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3635 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| Atul Bajaj | 1cc7329 | 2018-11-15 11:36:53 +0530 | [diff] [blame] | 3636 | if (abs_imm == 2) { |
| 3637 | __ movq(rdx, numerator); |
| 3638 | __ shrq(rdx, Immediate(63)); |
| 3639 | __ addq(rdx, numerator); |
| 3640 | } else { |
| 3641 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
| 3642 | __ addq(rdx, numerator); |
| 3643 | __ testq(numerator, numerator); |
| 3644 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3645 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3646 | int shift = CTZ(imm); |
| 3647 | __ sarq(rdx, Immediate(shift)); |
| 3648 | |
| 3649 | if (imm < 0) { |
| 3650 | __ negq(rdx); |
| 3651 | } |
| 3652 | |
| 3653 | __ movq(output_register, rdx); |
| 3654 | } |
| 3655 | } |
| 3656 | |
| 3657 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3658 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3659 | |
| 3660 | LocationSummary* locations = instruction->GetLocations(); |
| 3661 | Location second = locations->InAt(1); |
| 3662 | |
| 3663 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3664 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3665 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3666 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3667 | : locations->Out().AsRegister<CpuRegister>(); |
| 3668 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3669 | |
| 3670 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3671 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3672 | if (instruction->IsDiv()) { |
| 3673 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3674 | } else { |
| 3675 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3676 | } |
| 3677 | |
| 3678 | int64_t magic; |
| 3679 | int shift; |
| 3680 | |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3681 | // TODO: can these branches be written as one? |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3682 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3683 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3684 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3685 | CalculateMagicAndShiftForDivRem(imm, false /* is_long= */, &magic, &shift); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3686 | |
| 3687 | __ movl(numerator, eax); |
| 3688 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3689 | __ movl(eax, Immediate(magic)); |
| 3690 | __ imull(numerator); |
| 3691 | |
| 3692 | if (imm > 0 && magic < 0) { |
| 3693 | __ addl(edx, numerator); |
| 3694 | } else if (imm < 0 && magic > 0) { |
| 3695 | __ subl(edx, numerator); |
| 3696 | } |
| 3697 | |
| 3698 | if (shift != 0) { |
| 3699 | __ sarl(edx, Immediate(shift)); |
| 3700 | } |
| 3701 | |
| 3702 | __ movl(eax, edx); |
| 3703 | __ shrl(edx, Immediate(31)); |
| 3704 | __ addl(edx, eax); |
| 3705 | |
| 3706 | if (instruction->IsRem()) { |
| 3707 | __ movl(eax, numerator); |
| 3708 | __ imull(edx, Immediate(imm)); |
| 3709 | __ subl(eax, edx); |
| 3710 | __ movl(edx, eax); |
| 3711 | } else { |
| 3712 | __ movl(eax, edx); |
| 3713 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3714 | } else { |
| 3715 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3716 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3717 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3718 | |
| 3719 | CpuRegister rax = eax; |
| 3720 | CpuRegister rdx = edx; |
| 3721 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3722 | CalculateMagicAndShiftForDivRem(imm, true /* is_long= */, &magic, &shift); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3723 | |
| 3724 | // Save the numerator. |
| 3725 | __ movq(numerator, rax); |
| 3726 | |
| 3727 | // RAX = magic |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3728 | codegen_->Load64BitValue(rax, magic); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3729 | |
| 3730 | // RDX:RAX = magic * numerator |
| 3731 | __ imulq(numerator); |
| 3732 | |
| 3733 | if (imm > 0 && magic < 0) { |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3734 | // RDX += numerator |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3735 | __ addq(rdx, numerator); |
| 3736 | } else if (imm < 0 && magic > 0) { |
| 3737 | // RDX -= numerator |
| 3738 | __ subq(rdx, numerator); |
| 3739 | } |
| 3740 | |
| 3741 | // Shift if needed. |
| 3742 | if (shift != 0) { |
| 3743 | __ sarq(rdx, Immediate(shift)); |
| 3744 | } |
| 3745 | |
| 3746 | // RDX += 1 if RDX < 0 |
| 3747 | __ movq(rax, rdx); |
| 3748 | __ shrq(rdx, Immediate(63)); |
| 3749 | __ addq(rdx, rax); |
| 3750 | |
| 3751 | if (instruction->IsRem()) { |
| 3752 | __ movq(rax, numerator); |
| 3753 | |
| 3754 | if (IsInt<32>(imm)) { |
| 3755 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3756 | } else { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3757 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3758 | } |
| 3759 | |
| 3760 | __ subq(rax, rdx); |
| 3761 | __ movq(rdx, rax); |
| 3762 | } else { |
| 3763 | __ movq(rax, rdx); |
| 3764 | } |
| 3765 | } |
| 3766 | } |
| 3767 | |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3768 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3769 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3770 | DataType::Type type = instruction->GetResultType(); |
| 3771 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3772 | |
| 3773 | bool is_div = instruction->IsDiv(); |
| 3774 | LocationSummary* locations = instruction->GetLocations(); |
| 3775 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3776 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3777 | Location second = locations->InAt(1); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3778 | |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3779 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3780 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3781 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3782 | if (second.IsConstant()) { |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3783 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3784 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3785 | if (imm == 0) { |
| 3786 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3787 | } else if (imm == 1 || imm == -1) { |
| 3788 | DivRemOneOrMinusOne(instruction); |
| Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3789 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 3790 | if (is_div) { |
| 3791 | DivByPowerOfTwo(instruction->AsDiv()); |
| 3792 | } else { |
| 3793 | RemByPowerOfTwo(instruction->AsRem()); |
| 3794 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3795 | } else { |
| 3796 | DCHECK(imm <= -2 || imm >= 2); |
| 3797 | GenerateDivRemWithAnyConstant(instruction); |
| 3798 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3799 | } else { |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3800 | SlowPathCode* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3801 | new (codegen_->GetScopedAllocator()) DivRemMinusOneSlowPathX86_64( |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3802 | instruction, out.AsRegister(), type, is_div); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3803 | codegen_->AddSlowPath(slow_path); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3804 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3805 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3806 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3807 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3808 | // so it's safe to just use negl instead of more complex comparisons. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3809 | if (type == DataType::Type::kInt32) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3810 | __ cmpl(second_reg, Immediate(-1)); |
| 3811 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3812 | // edx:eax <- sign-extended of eax |
| 3813 | __ cdq(); |
| 3814 | // eax = quotient, edx = remainder |
| 3815 | __ idivl(second_reg); |
| 3816 | } else { |
| 3817 | __ cmpq(second_reg, Immediate(-1)); |
| 3818 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3819 | // rdx:rax <- sign-extended of rax |
| 3820 | __ cqo(); |
| 3821 | // rax = quotient, rdx = remainder |
| 3822 | __ idivq(second_reg); |
| 3823 | } |
| 3824 | __ Bind(slow_path->GetExitLabel()); |
| 3825 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3826 | } |
| 3827 | |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3828 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3829 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3830 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3831 | switch (div->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3832 | case DataType::Type::kInt32: |
| 3833 | case DataType::Type::kInt64: { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3834 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3835 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3836 | locations->SetOut(Location::SameAsFirstInput()); |
| 3837 | // Intel uses edx:eax as the dividend. |
| 3838 | locations->AddTemp(Location::RegisterLocation(RDX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3839 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3840 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3841 | // output and request another temp. |
| 3842 | if (div->InputAt(1)->IsConstant()) { |
| 3843 | locations->AddTemp(Location::RequiresRegister()); |
| 3844 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3845 | break; |
| 3846 | } |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3847 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3848 | case DataType::Type::kFloat32: |
| 3849 | case DataType::Type::kFloat64: { |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3850 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3851 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3852 | locations->SetOut(Location::SameAsFirstInput()); |
| 3853 | break; |
| 3854 | } |
| 3855 | |
| 3856 | default: |
| 3857 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3858 | } |
| 3859 | } |
| 3860 | |
| 3861 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3862 | LocationSummary* locations = div->GetLocations(); |
| 3863 | Location first = locations->InAt(0); |
| 3864 | Location second = locations->InAt(1); |
| 3865 | DCHECK(first.Equals(locations->Out())); |
| 3866 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3867 | DataType::Type type = div->GetResultType(); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3868 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3869 | case DataType::Type::kInt32: |
| 3870 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3871 | GenerateDivRemIntegral(div); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3872 | break; |
| 3873 | } |
| 3874 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3875 | case DataType::Type::kFloat32: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3876 | if (second.IsFpuRegister()) { |
| 3877 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3878 | } else if (second.IsConstant()) { |
| 3879 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3880 | codegen_->LiteralFloatAddress( |
| 3881 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3882 | } else { |
| 3883 | DCHECK(second.IsStackSlot()); |
| 3884 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3885 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3886 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3887 | break; |
| 3888 | } |
| 3889 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3890 | case DataType::Type::kFloat64: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3891 | if (second.IsFpuRegister()) { |
| 3892 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3893 | } else if (second.IsConstant()) { |
| 3894 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3895 | codegen_->LiteralDoubleAddress( |
| 3896 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3897 | } else { |
| 3898 | DCHECK(second.IsDoubleStackSlot()); |
| 3899 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3900 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3901 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3902 | break; |
| 3903 | } |
| 3904 | |
| 3905 | default: |
| 3906 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3907 | } |
| 3908 | } |
| 3909 | |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3910 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3911 | DataType::Type type = rem->GetResultType(); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3912 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3913 | new (GetGraph()->GetAllocator()) LocationSummary(rem, LocationSummary::kNoCall); |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3914 | |
| 3915 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3916 | case DataType::Type::kInt32: |
| 3917 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3918 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3919 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3920 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3921 | locations->SetOut(Location::RegisterLocation(RDX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3922 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3923 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3924 | // output and request another temp. |
| 3925 | if (rem->InputAt(1)->IsConstant()) { |
| 3926 | locations->AddTemp(Location::RequiresRegister()); |
| 3927 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3928 | break; |
| 3929 | } |
| 3930 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3931 | case DataType::Type::kFloat32: |
| 3932 | case DataType::Type::kFloat64: { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3933 | locations->SetInAt(0, Location::Any()); |
| 3934 | locations->SetInAt(1, Location::Any()); |
| 3935 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3936 | locations->AddTemp(Location::RegisterLocation(RAX)); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3937 | break; |
| 3938 | } |
| 3939 | |
| 3940 | default: |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3941 | LOG(FATAL) << "Unexpected rem type " << type; |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3942 | } |
| 3943 | } |
| 3944 | |
| 3945 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3946 | DataType::Type type = rem->GetResultType(); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3947 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3948 | case DataType::Type::kInt32: |
| 3949 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3950 | GenerateDivRemIntegral(rem); |
| 3951 | break; |
| 3952 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3953 | case DataType::Type::kFloat32: |
| 3954 | case DataType::Type::kFloat64: { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3955 | GenerateRemFP(rem); |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3956 | break; |
| 3957 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3958 | default: |
| 3959 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3960 | } |
| 3961 | } |
| 3962 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 3963 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 3964 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 3965 | switch (minmax->GetResultType()) { |
| 3966 | case DataType::Type::kInt32: |
| 3967 | case DataType::Type::kInt64: |
| 3968 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3969 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3970 | locations->SetOut(Location::SameAsFirstInput()); |
| 3971 | break; |
| 3972 | case DataType::Type::kFloat32: |
| 3973 | case DataType::Type::kFloat64: |
| 3974 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3975 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3976 | // The following is sub-optimal, but all we can do for now. It would be fine to also accept |
| 3977 | // the second input to be the output (we can simply swap inputs). |
| 3978 | locations->SetOut(Location::SameAsFirstInput()); |
| 3979 | break; |
| 3980 | default: |
| 3981 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 3982 | } |
| 3983 | } |
| 3984 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 3985 | void InstructionCodeGeneratorX86_64::GenerateMinMaxInt(LocationSummary* locations, |
| 3986 | bool is_min, |
| 3987 | DataType::Type type) { |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 3988 | Location op1_loc = locations->InAt(0); |
| 3989 | Location op2_loc = locations->InAt(1); |
| 3990 | |
| 3991 | // Shortcut for same input locations. |
| 3992 | if (op1_loc.Equals(op2_loc)) { |
| 3993 | // Can return immediately, as op1_loc == out_loc. |
| 3994 | // Note: if we ever support separate registers, e.g., output into memory, we need to check for |
| 3995 | // a copy here. |
| 3996 | DCHECK(locations->Out().Equals(op1_loc)); |
| 3997 | return; |
| 3998 | } |
| 3999 | |
| 4000 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4001 | CpuRegister op2 = op2_loc.AsRegister<CpuRegister>(); |
| 4002 | |
| 4003 | // (out := op1) |
| 4004 | // out <=? op2 |
| 4005 | // if out is min jmp done |
| 4006 | // out := op2 |
| 4007 | // done: |
| 4008 | |
| 4009 | if (type == DataType::Type::kInt64) { |
| 4010 | __ cmpq(out, op2); |
| 4011 | __ cmov(is_min ? Condition::kGreater : Condition::kLess, out, op2, /*is64bit*/ true); |
| 4012 | } else { |
| 4013 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 4014 | __ cmpl(out, op2); |
| 4015 | __ cmov(is_min ? Condition::kGreater : Condition::kLess, out, op2, /*is64bit*/ false); |
| 4016 | } |
| 4017 | } |
| 4018 | |
| 4019 | void InstructionCodeGeneratorX86_64::GenerateMinMaxFP(LocationSummary* locations, |
| 4020 | bool is_min, |
| 4021 | DataType::Type type) { |
| 4022 | Location op1_loc = locations->InAt(0); |
| 4023 | Location op2_loc = locations->InAt(1); |
| 4024 | Location out_loc = locations->Out(); |
| 4025 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| 4026 | |
| 4027 | // Shortcut for same input locations. |
| 4028 | if (op1_loc.Equals(op2_loc)) { |
| 4029 | DCHECK(out_loc.Equals(op1_loc)); |
| 4030 | return; |
| 4031 | } |
| 4032 | |
| 4033 | // (out := op1) |
| 4034 | // out <=? op2 |
| 4035 | // if Nan jmp Nan_label |
| 4036 | // if out is min jmp done |
| 4037 | // if op2 is min jmp op2_label |
| 4038 | // handle -0/+0 |
| 4039 | // jmp done |
| 4040 | // Nan_label: |
| 4041 | // out := NaN |
| 4042 | // op2_label: |
| 4043 | // out := op2 |
| 4044 | // done: |
| 4045 | // |
| 4046 | // This removes one jmp, but needs to copy one input (op1) to out. |
| 4047 | // |
| 4048 | // TODO: This is straight from Quick. Make NaN an out-of-line slowpath? |
| 4049 | |
| 4050 | XmmRegister op2 = op2_loc.AsFpuRegister<XmmRegister>(); |
| 4051 | |
| 4052 | NearLabel nan, done, op2_label; |
| 4053 | if (type == DataType::Type::kFloat64) { |
| 4054 | __ ucomisd(out, op2); |
| 4055 | } else { |
| 4056 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 4057 | __ ucomiss(out, op2); |
| 4058 | } |
| 4059 | |
| 4060 | __ j(Condition::kParityEven, &nan); |
| 4061 | |
| 4062 | __ j(is_min ? Condition::kAbove : Condition::kBelow, &op2_label); |
| 4063 | __ j(is_min ? Condition::kBelow : Condition::kAbove, &done); |
| 4064 | |
| 4065 | // Handle 0.0/-0.0. |
| 4066 | if (is_min) { |
| 4067 | if (type == DataType::Type::kFloat64) { |
| 4068 | __ orpd(out, op2); |
| 4069 | } else { |
| 4070 | __ orps(out, op2); |
| 4071 | } |
| 4072 | } else { |
| 4073 | if (type == DataType::Type::kFloat64) { |
| 4074 | __ andpd(out, op2); |
| 4075 | } else { |
| 4076 | __ andps(out, op2); |
| 4077 | } |
| 4078 | } |
| 4079 | __ jmp(&done); |
| 4080 | |
| 4081 | // NaN handling. |
| 4082 | __ Bind(&nan); |
| 4083 | if (type == DataType::Type::kFloat64) { |
| 4084 | __ movsd(out, codegen_->LiteralInt64Address(INT64_C(0x7FF8000000000000))); |
| 4085 | } else { |
| 4086 | __ movss(out, codegen_->LiteralInt32Address(INT32_C(0x7FC00000))); |
| 4087 | } |
| 4088 | __ jmp(&done); |
| 4089 | |
| 4090 | // out := op2; |
| 4091 | __ Bind(&op2_label); |
| 4092 | if (type == DataType::Type::kFloat64) { |
| 4093 | __ movsd(out, op2); |
| 4094 | } else { |
| 4095 | __ movss(out, op2); |
| 4096 | } |
| 4097 | |
| 4098 | // Done. |
| 4099 | __ Bind(&done); |
| 4100 | } |
| 4101 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4102 | void InstructionCodeGeneratorX86_64::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 4103 | DataType::Type type = minmax->GetResultType(); |
| 4104 | switch (type) { |
| 4105 | case DataType::Type::kInt32: |
| 4106 | case DataType::Type::kInt64: |
| 4107 | GenerateMinMaxInt(minmax->GetLocations(), is_min, type); |
| 4108 | break; |
| 4109 | case DataType::Type::kFloat32: |
| 4110 | case DataType::Type::kFloat64: |
| 4111 | GenerateMinMaxFP(minmax->GetLocations(), is_min, type); |
| 4112 | break; |
| 4113 | default: |
| 4114 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 4115 | } |
| 4116 | } |
| 4117 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4118 | void LocationsBuilderX86_64::VisitMin(HMin* min) { |
| 4119 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 4120 | } |
| 4121 | |
| 4122 | void InstructionCodeGeneratorX86_64::VisitMin(HMin* min) { |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4123 | GenerateMinMax(min, /*is_min*/ true); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4124 | } |
| 4125 | |
| 4126 | void LocationsBuilderX86_64::VisitMax(HMax* max) { |
| 4127 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 4128 | } |
| 4129 | |
| 4130 | void InstructionCodeGeneratorX86_64::VisitMax(HMax* max) { |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4131 | GenerateMinMax(max, /*is_min*/ false); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4132 | } |
| 4133 | |
| Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4134 | void LocationsBuilderX86_64::VisitAbs(HAbs* abs) { |
| 4135 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 4136 | switch (abs->GetResultType()) { |
| 4137 | case DataType::Type::kInt32: |
| 4138 | case DataType::Type::kInt64: |
| 4139 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4140 | locations->SetOut(Location::SameAsFirstInput()); |
| 4141 | locations->AddTemp(Location::RequiresRegister()); |
| 4142 | break; |
| 4143 | case DataType::Type::kFloat32: |
| 4144 | case DataType::Type::kFloat64: |
| 4145 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4146 | locations->SetOut(Location::SameAsFirstInput()); |
| 4147 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4148 | break; |
| 4149 | default: |
| 4150 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4151 | } |
| 4152 | } |
| 4153 | |
| 4154 | void InstructionCodeGeneratorX86_64::VisitAbs(HAbs* abs) { |
| 4155 | LocationSummary* locations = abs->GetLocations(); |
| 4156 | switch (abs->GetResultType()) { |
| 4157 | case DataType::Type::kInt32: { |
| 4158 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4159 | CpuRegister mask = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4160 | // Create mask. |
| 4161 | __ movl(mask, out); |
| 4162 | __ sarl(mask, Immediate(31)); |
| 4163 | // Add mask. |
| 4164 | __ addl(out, mask); |
| 4165 | __ xorl(out, mask); |
| 4166 | break; |
| 4167 | } |
| 4168 | case DataType::Type::kInt64: { |
| 4169 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4170 | CpuRegister mask = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4171 | // Create mask. |
| 4172 | __ movq(mask, out); |
| 4173 | __ sarq(mask, Immediate(63)); |
| 4174 | // Add mask. |
| 4175 | __ addq(out, mask); |
| 4176 | __ xorq(out, mask); |
| 4177 | break; |
| 4178 | } |
| 4179 | case DataType::Type::kFloat32: { |
| 4180 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4181 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4182 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x7FFFFFFF))); |
| 4183 | __ andps(out, mask); |
| 4184 | break; |
| 4185 | } |
| 4186 | case DataType::Type::kFloat64: { |
| 4187 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4188 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4189 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x7FFFFFFFFFFFFFFF))); |
| 4190 | __ andpd(out, mask); |
| 4191 | break; |
| 4192 | } |
| 4193 | default: |
| 4194 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4195 | } |
| 4196 | } |
| 4197 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4198 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4199 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4200 | locations->SetInAt(0, Location::Any()); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4201 | } |
| 4202 | |
| 4203 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4204 | SlowPathCode* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4205 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86_64(instruction); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4206 | codegen_->AddSlowPath(slow_path); |
| 4207 | |
| 4208 | LocationSummary* locations = instruction->GetLocations(); |
| 4209 | Location value = locations->InAt(0); |
| 4210 | |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4211 | switch (instruction->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4212 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4213 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4214 | case DataType::Type::kInt8: |
| 4215 | case DataType::Type::kUint16: |
| 4216 | case DataType::Type::kInt16: |
| 4217 | case DataType::Type::kInt32: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4218 | if (value.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4219 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4220 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4221 | } else if (value.IsStackSlot()) { |
| 4222 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 4223 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4224 | } else { |
| 4225 | DCHECK(value.IsConstant()) << value; |
| 4226 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4227 | __ jmp(slow_path->GetEntryLabel()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4228 | } |
| 4229 | } |
| 4230 | break; |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4231 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4232 | case DataType::Type::kInt64: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4233 | if (value.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4234 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4235 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4236 | } else if (value.IsDoubleStackSlot()) { |
| 4237 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 4238 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4239 | } else { |
| 4240 | DCHECK(value.IsConstant()) << value; |
| 4241 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4242 | __ jmp(slow_path->GetEntryLabel()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4243 | } |
| 4244 | } |
| 4245 | break; |
| 4246 | } |
| 4247 | default: |
| 4248 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4249 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4250 | } |
| 4251 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4252 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 4253 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4254 | |
| 4255 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4256 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4257 | |
| 4258 | switch (op->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4259 | case DataType::Type::kInt32: |
| 4260 | case DataType::Type::kInt64: { |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4261 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4262 | // The shift count needs to be in CL. |
| 4263 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 4264 | locations->SetOut(Location::SameAsFirstInput()); |
| 4265 | break; |
| 4266 | } |
| 4267 | default: |
| 4268 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 4269 | } |
| 4270 | } |
| 4271 | |
| 4272 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 4273 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4274 | |
| 4275 | LocationSummary* locations = op->GetLocations(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4276 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4277 | Location second = locations->InAt(1); |
| 4278 | |
| 4279 | switch (op->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4280 | case DataType::Type::kInt32: { |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4281 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4282 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4283 | if (op->IsShl()) { |
| 4284 | __ shll(first_reg, second_reg); |
| 4285 | } else if (op->IsShr()) { |
| 4286 | __ sarl(first_reg, second_reg); |
| 4287 | } else { |
| 4288 | __ shrl(first_reg, second_reg); |
| 4289 | } |
| 4290 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4291 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4292 | if (op->IsShl()) { |
| 4293 | __ shll(first_reg, imm); |
| 4294 | } else if (op->IsShr()) { |
| 4295 | __ sarl(first_reg, imm); |
| 4296 | } else { |
| 4297 | __ shrl(first_reg, imm); |
| 4298 | } |
| 4299 | } |
| 4300 | break; |
| 4301 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4302 | case DataType::Type::kInt64: { |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4303 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4304 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4305 | if (op->IsShl()) { |
| 4306 | __ shlq(first_reg, second_reg); |
| 4307 | } else if (op->IsShr()) { |
| 4308 | __ sarq(first_reg, second_reg); |
| 4309 | } else { |
| 4310 | __ shrq(first_reg, second_reg); |
| 4311 | } |
| 4312 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4313 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4314 | if (op->IsShl()) { |
| 4315 | __ shlq(first_reg, imm); |
| 4316 | } else if (op->IsShr()) { |
| 4317 | __ sarq(first_reg, imm); |
| 4318 | } else { |
| 4319 | __ shrq(first_reg, imm); |
| 4320 | } |
| 4321 | } |
| 4322 | break; |
| 4323 | } |
| 4324 | default: |
| 4325 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 4326 | UNREACHABLE(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4327 | } |
| 4328 | } |
| 4329 | |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4330 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 4331 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4332 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4333 | |
| 4334 | switch (ror->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4335 | case DataType::Type::kInt32: |
| 4336 | case DataType::Type::kInt64: { |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4337 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4338 | // The shift count needs to be in CL (unless it is a constant). |
| 4339 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 4340 | locations->SetOut(Location::SameAsFirstInput()); |
| 4341 | break; |
| 4342 | } |
| 4343 | default: |
| 4344 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4345 | UNREACHABLE(); |
| 4346 | } |
| 4347 | } |
| 4348 | |
| 4349 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 4350 | LocationSummary* locations = ror->GetLocations(); |
| 4351 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4352 | Location second = locations->InAt(1); |
| 4353 | |
| 4354 | switch (ror->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4355 | case DataType::Type::kInt32: |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4356 | if (second.IsRegister()) { |
| 4357 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4358 | __ rorl(first_reg, second_reg); |
| 4359 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4360 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4361 | __ rorl(first_reg, imm); |
| 4362 | } |
| 4363 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4364 | case DataType::Type::kInt64: |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4365 | if (second.IsRegister()) { |
| 4366 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4367 | __ rorq(first_reg, second_reg); |
| 4368 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4369 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4370 | __ rorq(first_reg, imm); |
| 4371 | } |
| 4372 | break; |
| 4373 | default: |
| 4374 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4375 | UNREACHABLE(); |
| 4376 | } |
| 4377 | } |
| 4378 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4379 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 4380 | HandleShift(shl); |
| 4381 | } |
| 4382 | |
| 4383 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 4384 | HandleShift(shl); |
| 4385 | } |
| 4386 | |
| 4387 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 4388 | HandleShift(shr); |
| 4389 | } |
| 4390 | |
| 4391 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 4392 | HandleShift(shr); |
| 4393 | } |
| 4394 | |
| 4395 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 4396 | HandleShift(ushr); |
| 4397 | } |
| 4398 | |
| 4399 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 4400 | HandleShift(ushr); |
| 4401 | } |
| 4402 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4403 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4404 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4405 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4406 | InvokeRuntimeCallingConvention calling_convention; |
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4407 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4408 | locations->SetOut(Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4409 | } |
| 4410 | |
| 4411 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4412 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 4413 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 4414 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4415 | } |
| 4416 | |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4417 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4418 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4419 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4420 | InvokeRuntimeCallingConvention calling_convention; |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4421 | locations->SetOut(Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4422 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4423 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4424 | } |
| 4425 | |
| 4426 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 4427 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 4428 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
| Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 4429 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4430 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4431 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4432 | } |
| 4433 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4434 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4435 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4436 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4437 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4438 | if (location.IsStackSlot()) { |
| 4439 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4440 | } else if (location.IsDoubleStackSlot()) { |
| 4441 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4442 | } |
| 4443 | locations->SetOut(location); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4444 | } |
| 4445 | |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4446 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 4447 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4448 | // Nothing to do, the parameter is already at its location. |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4449 | } |
| 4450 | |
| 4451 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4452 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4453 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4454 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4455 | } |
| 4456 | |
| 4457 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 4458 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4459 | // Nothing to do, the method is already at its location. |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4460 | } |
| 4461 | |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4462 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4463 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4464 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4465 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4466 | locations->SetOut(Location::RequiresRegister()); |
| 4467 | } |
| 4468 | |
| 4469 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4470 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4471 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4472 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4473 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4474 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4475 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4476 | } else { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4477 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4478 | instruction->GetIndex(), kX86_64PointerSize)); |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4479 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4480 | Address(locations->InAt(0).AsRegister<CpuRegister>(), |
| 4481 | mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4482 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4483 | Address(locations->Out().AsRegister<CpuRegister>(), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4484 | } |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4485 | } |
| 4486 | |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4487 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4488 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4489 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4490 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4491 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4492 | } |
| 4493 | |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4494 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 4495 | LocationSummary* locations = not_->GetLocations(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4496 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4497 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4498 | Location out = locations->Out(); |
| Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4499 | switch (not_->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4500 | case DataType::Type::kInt32: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4501 | __ notl(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4502 | break; |
| 4503 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4504 | case DataType::Type::kInt64: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4505 | __ notq(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4506 | break; |
| 4507 | |
| 4508 | default: |
| 4509 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4510 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4511 | } |
| 4512 | |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4513 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4514 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4515 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4516 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4517 | locations->SetOut(Location::SameAsFirstInput()); |
| 4518 | } |
| 4519 | |
| 4520 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4521 | LocationSummary* locations = bool_not->GetLocations(); |
| 4522 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4523 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 4524 | Location out = locations->Out(); |
| 4525 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 4526 | } |
| 4527 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4528 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4529 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4530 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4531 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4532 | locations->SetInAt(i, Location::Any()); |
| 4533 | } |
| 4534 | locations->SetOut(Location::Any()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4535 | } |
| 4536 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4537 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4538 | LOG(FATAL) << "Unimplemented"; |
| 4539 | } |
| 4540 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4541 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4542 | /* |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4543 | * According to the JSR-133 Cookbook, for x86-64 only StoreLoad/AnyAny barriers need memory fence. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4544 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86-64 memory model. |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4545 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4546 | */ |
| 4547 | switch (kind) { |
| 4548 | case MemBarrierKind::kAnyAny: { |
| Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4549 | MemoryFence(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4550 | break; |
| 4551 | } |
| 4552 | case MemBarrierKind::kAnyStore: |
| 4553 | case MemBarrierKind::kLoadAny: |
| 4554 | case MemBarrierKind::kStoreStore: { |
| 4555 | // nop |
| 4556 | break; |
| 4557 | } |
| Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4558 | case MemBarrierKind::kNTStoreStore: |
| 4559 | // Non-Temporal Store/Store needs an explicit fence. |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4560 | MemoryFence(/* non-temporal= */ true); |
| Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4561 | break; |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4562 | } |
| 4563 | } |
| 4564 | |
| 4565 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4566 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4567 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4568 | bool object_field_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4569 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4570 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4571 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 4572 | object_field_get_with_read_barrier |
| 4573 | ? LocationSummary::kCallOnSlowPath |
| 4574 | : LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4575 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4576 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4577 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4578 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4579 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4580 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4581 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4582 | // The output overlaps for an object field get when read barriers |
| 4583 | // are enabled: we do not want the move to overwrite the object's |
| 4584 | // location, as we need it to emit the read barrier. |
| 4585 | locations->SetOut( |
| 4586 | Location::RequiresRegister(), |
| 4587 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4588 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4589 | } |
| 4590 | |
| 4591 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4592 | const FieldInfo& field_info) { |
| 4593 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4594 | |
| 4595 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4596 | Location base_loc = locations->InAt(0); |
| 4597 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4598 | Location out = locations->Out(); |
| 4599 | bool is_volatile = field_info.IsVolatile(); |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4600 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 4601 | DataType::Type load_type = instruction->GetType(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4602 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4603 | |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4604 | switch (load_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4605 | case DataType::Type::kBool: |
| 4606 | case DataType::Type::kUint8: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4607 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4608 | break; |
| 4609 | } |
| 4610 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4611 | case DataType::Type::kInt8: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4612 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4613 | break; |
| 4614 | } |
| 4615 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4616 | case DataType::Type::kUint16: { |
| 4617 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4618 | break; |
| 4619 | } |
| 4620 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4621 | case DataType::Type::kInt16: { |
| 4622 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4623 | break; |
| 4624 | } |
| 4625 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4626 | case DataType::Type::kInt32: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4627 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4628 | break; |
| 4629 | } |
| 4630 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4631 | case DataType::Type::kReference: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4632 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4633 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4634 | // Note that a potential implicit null check is handled in this |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 4635 | // CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier call. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4636 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4637 | instruction, out, base, offset, /* needs_null_check= */ true); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4638 | if (is_volatile) { |
| 4639 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4640 | } |
| 4641 | } else { |
| 4642 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4643 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4644 | if (is_volatile) { |
| 4645 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4646 | } |
| 4647 | // If read barriers are enabled, emit read barriers other than |
| 4648 | // Baker's using a slow path (and also unpoison the loaded |
| 4649 | // reference, if heap poisoning is enabled). |
| 4650 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4651 | } |
| 4652 | break; |
| 4653 | } |
| 4654 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4655 | case DataType::Type::kInt64: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4656 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4657 | break; |
| 4658 | } |
| 4659 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4660 | case DataType::Type::kFloat32: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4661 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4662 | break; |
| 4663 | } |
| 4664 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4665 | case DataType::Type::kFloat64: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4666 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4667 | break; |
| 4668 | } |
| 4669 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 4670 | case DataType::Type::kUint32: |
| 4671 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4672 | case DataType::Type::kVoid: |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4673 | LOG(FATAL) << "Unreachable type " << load_type; |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4674 | UNREACHABLE(); |
| 4675 | } |
| 4676 | |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4677 | if (load_type == DataType::Type::kReference) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4678 | // Potential implicit null checks, in the case of reference |
| 4679 | // fields, are handled in the previous switch statement. |
| 4680 | } else { |
| 4681 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4682 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4683 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4684 | if (is_volatile) { |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4685 | if (load_type == DataType::Type::kReference) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4686 | // Memory barriers, in the case of references, are also handled |
| 4687 | // in the previous switch statement. |
| 4688 | } else { |
| 4689 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4690 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4691 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4692 | } |
| 4693 | |
| 4694 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4695 | const FieldInfo& field_info) { |
| 4696 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4697 | |
| 4698 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4699 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4700 | DataType::Type field_type = field_info.GetFieldType(); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4701 | bool is_volatile = field_info.IsVolatile(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4702 | bool needs_write_barrier = |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4703 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4704 | |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4705 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4706 | if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4707 | if (is_volatile) { |
| 4708 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4709 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4710 | } else { |
| 4711 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4712 | } |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4713 | } else { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4714 | if (is_volatile) { |
| 4715 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4716 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4717 | } else { |
| 4718 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4719 | } |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4720 | } |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4721 | if (needs_write_barrier) { |
| Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4722 | // Temporary registers for the write barrier. |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4723 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4724 | locations->AddTemp(Location::RequiresRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4725 | } else if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4726 | // Temporary register for the reference poisoning. |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4727 | locations->AddTemp(Location::RequiresRegister()); |
| 4728 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4729 | } |
| 4730 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4731 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4732 | const FieldInfo& field_info, |
| 4733 | bool value_can_be_null) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4734 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4735 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4736 | LocationSummary* locations = instruction->GetLocations(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4737 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4738 | Location value = locations->InAt(1); |
| 4739 | bool is_volatile = field_info.IsVolatile(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4740 | DataType::Type field_type = field_info.GetFieldType(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4741 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4742 | |
| 4743 | if (is_volatile) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4744 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4745 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4746 | |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4747 | bool maybe_record_implicit_null_check_done = false; |
| 4748 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4749 | switch (field_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4750 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4751 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4752 | case DataType::Type::kInt8: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4753 | if (value.IsConstant()) { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4754 | __ movb(Address(base, offset), |
| 4755 | Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4756 | } else { |
| 4757 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4758 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4759 | break; |
| 4760 | } |
| 4761 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4762 | case DataType::Type::kUint16: |
| 4763 | case DataType::Type::kInt16: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4764 | if (value.IsConstant()) { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4765 | __ movw(Address(base, offset), |
| 4766 | Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4767 | } else { |
| 4768 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4769 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4770 | break; |
| 4771 | } |
| 4772 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4773 | case DataType::Type::kInt32: |
| 4774 | case DataType::Type::kReference: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4775 | if (value.IsConstant()) { |
| 4776 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4777 | // `field_type == DataType::Type::kReference` implies `v == 0`. |
| 4778 | DCHECK((field_type != DataType::Type::kReference) || (v == 0)); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4779 | // Note: if heap poisoning is enabled, no need to poison |
| 4780 | // (negate) `v` if it is a reference, as it would be null. |
| Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4781 | __ movl(Address(base, offset), Immediate(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4782 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4783 | if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4784 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4785 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4786 | __ PoisonHeapReference(temp); |
| 4787 | __ movl(Address(base, offset), temp); |
| 4788 | } else { |
| 4789 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4790 | } |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4791 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4792 | break; |
| 4793 | } |
| 4794 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4795 | case DataType::Type::kInt64: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4796 | if (value.IsConstant()) { |
| 4797 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4798 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4799 | Address(base, offset + sizeof(int32_t)), |
| 4800 | v, |
| 4801 | instruction); |
| 4802 | maybe_record_implicit_null_check_done = true; |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4803 | } else { |
| 4804 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4805 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4806 | break; |
| 4807 | } |
| 4808 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4809 | case DataType::Type::kFloat32: { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4810 | if (value.IsConstant()) { |
| 4811 | int32_t v = |
| 4812 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4813 | __ movl(Address(base, offset), Immediate(v)); |
| 4814 | } else { |
| 4815 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4816 | } |
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4817 | break; |
| 4818 | } |
| 4819 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4820 | case DataType::Type::kFloat64: { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4821 | if (value.IsConstant()) { |
| 4822 | int64_t v = |
| 4823 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4824 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4825 | Address(base, offset + sizeof(int32_t)), |
| 4826 | v, |
| 4827 | instruction); |
| 4828 | maybe_record_implicit_null_check_done = true; |
| 4829 | } else { |
| 4830 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4831 | } |
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4832 | break; |
| 4833 | } |
| 4834 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 4835 | case DataType::Type::kUint32: |
| 4836 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4837 | case DataType::Type::kVoid: |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4838 | LOG(FATAL) << "Unreachable type " << field_type; |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4839 | UNREACHABLE(); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4840 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4841 | |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4842 | if (!maybe_record_implicit_null_check_done) { |
| 4843 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4844 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4845 | |
| 4846 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4847 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4848 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4849 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4850 | } |
| 4851 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4852 | if (is_volatile) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4853 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4854 | } |
| 4855 | } |
| 4856 | |
| 4857 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4858 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4859 | } |
| 4860 | |
| 4861 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4862 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4863 | } |
| 4864 | |
| 4865 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4866 | HandleFieldGet(instruction); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4867 | } |
| 4868 | |
| 4869 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4870 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4871 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4872 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4873 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4874 | HandleFieldGet(instruction); |
| 4875 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4876 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4877 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4878 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4879 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4880 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4881 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4882 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4883 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4884 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4885 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4886 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4887 | } |
| 4888 | |
| Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 4889 | void LocationsBuilderX86_64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 4890 | codegen_->CreateStringBuilderAppendLocations(instruction, Location::RegisterLocation(RAX)); |
| 4891 | } |
| 4892 | |
| 4893 | void InstructionCodeGeneratorX86_64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 4894 | __ movl(CpuRegister(RDI), Immediate(instruction->GetFormat()->GetValue())); |
| 4895 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 4896 | } |
| 4897 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4898 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4899 | HUnresolvedInstanceFieldGet* instruction) { |
| 4900 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4901 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4902 | instruction, instruction->GetFieldType(), calling_convention); |
| 4903 | } |
| 4904 | |
| 4905 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4906 | HUnresolvedInstanceFieldGet* instruction) { |
| 4907 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4908 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4909 | instruction->GetFieldType(), |
| 4910 | instruction->GetFieldIndex(), |
| 4911 | instruction->GetDexPc(), |
| 4912 | calling_convention); |
| 4913 | } |
| 4914 | |
| 4915 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4916 | HUnresolvedInstanceFieldSet* instruction) { |
| 4917 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4918 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4919 | instruction, instruction->GetFieldType(), calling_convention); |
| 4920 | } |
| 4921 | |
| 4922 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4923 | HUnresolvedInstanceFieldSet* instruction) { |
| 4924 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4925 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4926 | instruction->GetFieldType(), |
| 4927 | instruction->GetFieldIndex(), |
| 4928 | instruction->GetDexPc(), |
| 4929 | calling_convention); |
| 4930 | } |
| 4931 | |
| 4932 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 4933 | HUnresolvedStaticFieldGet* instruction) { |
| 4934 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4935 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4936 | instruction, instruction->GetFieldType(), calling_convention); |
| 4937 | } |
| 4938 | |
| 4939 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4940 | HUnresolvedStaticFieldGet* instruction) { |
| 4941 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4942 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4943 | instruction->GetFieldType(), |
| 4944 | instruction->GetFieldIndex(), |
| 4945 | instruction->GetDexPc(), |
| 4946 | calling_convention); |
| 4947 | } |
| 4948 | |
| 4949 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 4950 | HUnresolvedStaticFieldSet* instruction) { |
| 4951 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4952 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4953 | instruction, instruction->GetFieldType(), calling_convention); |
| 4954 | } |
| 4955 | |
| 4956 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 4957 | HUnresolvedStaticFieldSet* instruction) { |
| 4958 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4959 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4960 | instruction->GetFieldType(), |
| 4961 | instruction->GetFieldIndex(), |
| 4962 | instruction->GetDexPc(), |
| 4963 | calling_convention); |
| 4964 | } |
| 4965 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4966 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4967 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4968 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 4969 | ? Location::RequiresRegister() |
| 4970 | : Location::Any(); |
| 4971 | locations->SetInAt(0, loc); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4972 | } |
| 4973 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4974 | void CodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4975 | if (CanMoveNullCheckToUser(instruction)) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4976 | return; |
| 4977 | } |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4978 | LocationSummary* locations = instruction->GetLocations(); |
| 4979 | Location obj = locations->InAt(0); |
| 4980 | |
| 4981 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4982 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4983 | } |
| 4984 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4985 | void CodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4986 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86_64(instruction); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4987 | AddSlowPath(slow_path); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4988 | |
| 4989 | LocationSummary* locations = instruction->GetLocations(); |
| 4990 | Location obj = locations->InAt(0); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4991 | |
| 4992 | if (obj.IsRegister()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4993 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4994 | } else if (obj.IsStackSlot()) { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4995 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4996 | } else { |
| 4997 | DCHECK(obj.IsConstant()) << obj; |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4998 | DCHECK(obj.GetConstant()->IsNullConstant()); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4999 | __ jmp(slow_path->GetEntryLabel()); |
| 5000 | return; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5001 | } |
| 5002 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5003 | } |
| 5004 | |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5005 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5006 | codegen_->GenerateNullCheck(instruction); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5007 | } |
| 5008 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5009 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5010 | bool object_array_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5011 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5012 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5013 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5014 | object_array_get_with_read_barrier |
| 5015 | ? LocationSummary::kCallOnSlowPath |
| 5016 | : LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5017 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5018 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5019 | } |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5020 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5021 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5022 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5023 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5024 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5025 | // The output overlaps for an object array get when read barriers |
| 5026 | // are enabled: we do not want the move to overwrite the array's |
| 5027 | // location, as we need it to emit the read barrier. |
| 5028 | locations->SetOut( |
| 5029 | Location::RequiresRegister(), |
| 5030 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5031 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5032 | } |
| 5033 | |
| 5034 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 5035 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5036 | Location obj_loc = locations->InAt(0); |
| 5037 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5038 | Location index = locations->InAt(1); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5039 | Location out_loc = locations->Out(); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5040 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5041 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5042 | DataType::Type type = instruction->GetType(); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5043 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5044 | case DataType::Type::kBool: |
| 5045 | case DataType::Type::kUint8: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5046 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5047 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5048 | break; |
| 5049 | } |
| 5050 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5051 | case DataType::Type::kInt8: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5052 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5053 | __ movsxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5054 | break; |
| 5055 | } |
| 5056 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5057 | case DataType::Type::kUint16: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5058 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5059 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5060 | // Branch cases into compressed and uncompressed for each index's type. |
| 5061 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5062 | NearLabel done, not_compressed; |
| Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 5063 | __ testb(Address(obj, count_offset), Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5064 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5065 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5066 | "Expecting 0=compressed, 1=uncompressed"); |
| 5067 | __ j(kNotZero, ¬_compressed); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5068 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5069 | __ jmp(&done); |
| 5070 | __ Bind(¬_compressed); |
| 5071 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5072 | __ Bind(&done); |
| 5073 | } else { |
| 5074 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5075 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5076 | break; |
| 5077 | } |
| 5078 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5079 | case DataType::Type::kInt16: { |
| 5080 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| 5081 | __ movsxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5082 | break; |
| 5083 | } |
| 5084 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5085 | case DataType::Type::kInt32: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5086 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5087 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5088 | break; |
| 5089 | } |
| 5090 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5091 | case DataType::Type::kReference: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5092 | static_assert( |
| 5093 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5094 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5095 | // /* HeapReference<Object> */ out = |
| 5096 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5097 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5098 | // Note that a potential implicit null check is handled in this |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5099 | // CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier call. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5100 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5101 | instruction, out_loc, obj, data_offset, index, /* needs_null_check= */ true); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5102 | } else { |
| 5103 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5104 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5105 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5106 | // If read barriers are enabled, emit read barriers other than |
| 5107 | // Baker's using a slow path (and also unpoison the loaded |
| 5108 | // reference, if heap poisoning is enabled). |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5109 | if (index.IsConstant()) { |
| 5110 | uint32_t offset = |
| 5111 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5112 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5113 | } else { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5114 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5115 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5116 | } |
| 5117 | } |
| 5118 | break; |
| 5119 | } |
| 5120 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5121 | case DataType::Type::kInt64: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5122 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5123 | __ movq(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5124 | break; |
| 5125 | } |
| 5126 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5127 | case DataType::Type::kFloat32: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5128 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5129 | __ movss(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5130 | break; |
| 5131 | } |
| 5132 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5133 | case DataType::Type::kFloat64: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5134 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5135 | __ movsd(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5136 | break; |
| 5137 | } |
| 5138 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5139 | case DataType::Type::kUint32: |
| 5140 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5141 | case DataType::Type::kVoid: |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5142 | LOG(FATAL) << "Unreachable type " << type; |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5143 | UNREACHABLE(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5144 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5145 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5146 | if (type == DataType::Type::kReference) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5147 | // Potential implicit null checks, in the case of reference |
| 5148 | // arrays, are handled in the previous switch statement. |
| 5149 | } else { |
| 5150 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5151 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5152 | } |
| 5153 | |
| 5154 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5155 | DataType::Type value_type = instruction->GetComponentType(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5156 | |
| 5157 | bool needs_write_barrier = |
| 5158 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5159 | bool needs_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5160 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5161 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5162 | instruction, |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5163 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5164 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5165 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5166 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5167 | if (DataType::IsFloatingPointType(value_type)) { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5168 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5169 | } else { |
| 5170 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5171 | } |
| 5172 | |
| 5173 | if (needs_write_barrier) { |
| 5174 | // Temporary registers for the write barrier. |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5175 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5176 | locations->AddTemp(Location::RequiresRegister()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5177 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5178 | } |
| 5179 | |
| 5180 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 5181 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5182 | Location array_loc = locations->InAt(0); |
| 5183 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5184 | Location index = locations->InAt(1); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5185 | Location value = locations->InAt(2); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5186 | DataType::Type value_type = instruction->GetComponentType(); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5187 | bool needs_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5188 | bool needs_write_barrier = |
| 5189 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5190 | |
| 5191 | switch (value_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5192 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5193 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5194 | case DataType::Type::kInt8: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5195 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5196 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_1, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5197 | if (value.IsRegister()) { |
| 5198 | __ movb(address, value.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5199 | } else { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5200 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5201 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5202 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5203 | break; |
| 5204 | } |
| 5205 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5206 | case DataType::Type::kUint16: |
| 5207 | case DataType::Type::kInt16: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5208 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5209 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_2, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5210 | if (value.IsRegister()) { |
| 5211 | __ movw(address, value.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5212 | } else { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5213 | DCHECK(value.IsConstant()) << value; |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5214 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5215 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5216 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5217 | break; |
| 5218 | } |
| 5219 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5220 | case DataType::Type::kReference: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5221 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5222 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5223 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5224 | if (!value.IsRegister()) { |
| 5225 | // Just setting null. |
| 5226 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5227 | DCHECK(value.IsConstant()) << value; |
| 5228 | __ movl(address, Immediate(0)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5229 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5230 | DCHECK(!needs_write_barrier); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5231 | DCHECK(!needs_type_check); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5232 | break; |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5233 | } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5234 | |
| 5235 | DCHECK(needs_write_barrier); |
| 5236 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5237 | Location temp_loc = locations->GetTemp(0); |
| 5238 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5239 | |
| 5240 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 5241 | NearLabel do_store; |
| 5242 | if (can_value_be_null) { |
| 5243 | __ testl(register_value, register_value); |
| 5244 | __ j(kEqual, &do_store); |
| 5245 | } |
| 5246 | |
| 5247 | SlowPathCode* slow_path = nullptr; |
| 5248 | if (needs_type_check) { |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5249 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86_64(instruction); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5250 | codegen_->AddSlowPath(slow_path); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5251 | |
| 5252 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5253 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5254 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5255 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5256 | // Note that when Baker read barriers are enabled, the type |
| 5257 | // checks are performed without read barriers. This is fine, |
| 5258 | // even in the case where a class object is in the from-space |
| 5259 | // after the flip, as a comparison involving such a type would |
| 5260 | // not produce a false positive; it may of course produce a |
| 5261 | // false negative, in which case we would take the ArraySet |
| 5262 | // slow path. |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5263 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5264 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5265 | __ movl(temp, Address(array, class_offset)); |
| 5266 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5267 | __ MaybeUnpoisonHeapReference(temp); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5268 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5269 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5270 | __ movl(temp, Address(temp, component_offset)); |
| 5271 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5272 | // nor the object reference in `register_value->klass`, as |
| 5273 | // we are comparing two poisoned references. |
| 5274 | __ cmpl(temp, Address(register_value, class_offset)); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5275 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5276 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5277 | NearLabel do_put; |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5278 | __ j(kEqual, &do_put); |
| 5279 | // If heap poisoning is enabled, the `temp` reference has |
| 5280 | // not been unpoisoned yet; unpoison it now. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5281 | __ MaybeUnpoisonHeapReference(temp); |
| 5282 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5283 | // If heap poisoning is enabled, no need to unpoison the |
| 5284 | // heap reference loaded below, as it is only used for a |
| 5285 | // comparison with null. |
| 5286 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5287 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5288 | __ Bind(&do_put); |
| 5289 | } else { |
| 5290 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5291 | } |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5292 | } |
| 5293 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5294 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 5295 | codegen_->MarkGCCard( |
| 5296 | temp, card, array, value.AsRegister<CpuRegister>(), /* value_can_be_null= */ false); |
| 5297 | |
| 5298 | if (can_value_be_null) { |
| 5299 | DCHECK(do_store.IsLinked()); |
| 5300 | __ Bind(&do_store); |
| 5301 | } |
| 5302 | |
| 5303 | Location source = value; |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5304 | if (kPoisonHeapReferences) { |
| 5305 | __ movl(temp, register_value); |
| 5306 | __ PoisonHeapReference(temp); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5307 | source = temp_loc; |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5308 | } |
| 5309 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5310 | __ movl(address, source.AsRegister<CpuRegister>()); |
| 5311 | |
| 5312 | if (can_value_be_null || !needs_type_check) { |
| 5313 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5314 | } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5315 | |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5316 | if (slow_path != nullptr) { |
| 5317 | __ Bind(slow_path->GetExitLabel()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5318 | } |
| 5319 | |
| 5320 | break; |
| 5321 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5322 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5323 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5324 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5325 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5326 | if (value.IsRegister()) { |
| 5327 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 5328 | } else { |
| 5329 | DCHECK(value.IsConstant()) << value; |
| 5330 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5331 | __ movl(address, Immediate(v)); |
| 5332 | } |
| 5333 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5334 | break; |
| 5335 | } |
| 5336 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5337 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5338 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5339 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5340 | if (value.IsRegister()) { |
| 5341 | __ movq(address, value.AsRegister<CpuRegister>()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5342 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5343 | } else { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5344 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5345 | Address address_high = |
| 5346 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5347 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5348 | } |
| 5349 | break; |
| 5350 | } |
| 5351 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5352 | case DataType::Type::kFloat32: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5353 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5354 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5355 | if (value.IsFpuRegister()) { |
| 5356 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5357 | } else { |
| 5358 | DCHECK(value.IsConstant()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5359 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5360 | __ movl(address, Immediate(v)); |
| 5361 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5362 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5363 | break; |
| 5364 | } |
| 5365 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5366 | case DataType::Type::kFloat64: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5367 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5368 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5369 | if (value.IsFpuRegister()) { |
| 5370 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5371 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5372 | } else { |
| 5373 | int64_t v = |
| 5374 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5375 | Address address_high = |
| 5376 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5377 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 5378 | } |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5379 | break; |
| 5380 | } |
| 5381 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5382 | case DataType::Type::kUint32: |
| 5383 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5384 | case DataType::Type::kVoid: |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5385 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5386 | UNREACHABLE(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5387 | } |
| 5388 | } |
| 5389 | |
| 5390 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5391 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5392 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5393 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5394 | if (!instruction->IsEmittedAtUseSite()) { |
| 5395 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5396 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5397 | } |
| 5398 | |
| 5399 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5400 | if (instruction->IsEmittedAtUseSite()) { |
| 5401 | return; |
| 5402 | } |
| 5403 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5404 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5405 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5406 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5407 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5408 | __ movl(out, Address(obj, offset)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5409 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5410 | // Mask out most significant bit in case the array is String's array of char. |
| 5411 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5412 | __ shrl(out, Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5413 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5414 | } |
| 5415 | |
| 5416 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5417 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5418 | InvokeRuntimeCallingConvention calling_convention; |
| 5419 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5420 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5421 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5422 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5423 | HInstruction* length = instruction->InputAt(1); |
| 5424 | if (!length->IsEmittedAtUseSite()) { |
| 5425 | locations->SetInAt(1, Location::RegisterOrConstant(length)); |
| 5426 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5427 | } |
| 5428 | |
| 5429 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5430 | LocationSummary* locations = instruction->GetLocations(); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5431 | Location index_loc = locations->InAt(0); |
| 5432 | Location length_loc = locations->InAt(1); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5433 | SlowPathCode* slow_path = |
| 5434 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86_64(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5435 | |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5436 | if (length_loc.IsConstant()) { |
| 5437 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5438 | if (index_loc.IsConstant()) { |
| 5439 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5440 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5441 | if (index < 0 || index >= length) { |
| 5442 | codegen_->AddSlowPath(slow_path); |
| 5443 | __ jmp(slow_path->GetEntryLabel()); |
| 5444 | } else { |
| 5445 | // Some optimization after BCE may have generated this, and we should not |
| 5446 | // generate a bounds check if it is a valid range. |
| 5447 | } |
| 5448 | return; |
| 5449 | } |
| 5450 | |
| 5451 | // We have to reverse the jump condition because the length is the constant. |
| 5452 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 5453 | __ cmpl(index_reg, Immediate(length)); |
| 5454 | codegen_->AddSlowPath(slow_path); |
| 5455 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5456 | } else { |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5457 | HInstruction* array_length = instruction->InputAt(1); |
| 5458 | if (array_length->IsEmittedAtUseSite()) { |
| 5459 | // Address the length field in the array. |
| 5460 | DCHECK(array_length->IsArrayLength()); |
| 5461 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5462 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5463 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5464 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5465 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5466 | // the string compression flag) with the in-memory length and avoid the temporary. |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5467 | CpuRegister length_reg = CpuRegister(TMP); |
| 5468 | __ movl(length_reg, array_len); |
| 5469 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5470 | __ shrl(length_reg, Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5471 | codegen_->GenerateIntCompare(length_reg, index_loc); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5472 | } else { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5473 | // Checking the bound for general case: |
| 5474 | // Array of char or String's array when the compression feature off. |
| 5475 | if (index_loc.IsConstant()) { |
| 5476 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5477 | __ cmpl(array_len, Immediate(value)); |
| 5478 | } else { |
| 5479 | __ cmpl(array_len, index_loc.AsRegister<CpuRegister>()); |
| 5480 | } |
| 5481 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5482 | } |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5483 | } else { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5484 | codegen_->GenerateIntCompare(length_loc, index_loc); |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5485 | } |
| 5486 | codegen_->AddSlowPath(slow_path); |
| 5487 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5488 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5489 | } |
| 5490 | |
| 5491 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 5492 | CpuRegister card, |
| 5493 | CpuRegister object, |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5494 | CpuRegister value, |
| 5495 | bool value_can_be_null) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5496 | NearLabel is_null; |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5497 | if (value_can_be_null) { |
| 5498 | __ testl(value, value); |
| 5499 | __ j(kEqual, &is_null); |
| 5500 | } |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5501 | // Load the address of the card table into `card`. |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5502 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64PointerSize>().Int32Value(), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5503 | /* no_rip= */ true)); |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5504 | // Calculate the offset (in the card table) of the card corresponding to |
| 5505 | // `object`. |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5506 | __ movq(temp, object); |
| 5507 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5508 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 5509 | // `object`'s card. |
| 5510 | // |
| 5511 | // Register `card` contains the address of the card table. Note that the card |
| 5512 | // table's base is biased during its creation so that it always starts at an |
| 5513 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 5514 | // art::gc::accounting::CardTable::Create). Therefore the MOVB instruction |
| 5515 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 5516 | // (located at `card + object >> kCardShift`). |
| 5517 | // |
| 5518 | // This dual use of the value in register `card` (1. to calculate the location |
| 5519 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 5520 | // (no need to explicitly load `kCardDirty` as an immediate value). |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5521 | __ movb(Address(temp, card, TIMES_1, 0), card); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5522 | if (value_can_be_null) { |
| 5523 | __ Bind(&is_null); |
| 5524 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5525 | } |
| 5526 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5527 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5528 | LOG(FATAL) << "Unimplemented"; |
| 5529 | } |
| 5530 | |
| 5531 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
| Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5532 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5533 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5534 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5535 | // The back edge will generate the suspend check. |
| 5536 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5537 | } |
| 5538 | |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5539 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5540 | } |
| 5541 | |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5542 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5543 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5544 | instruction, LocationSummary::kCallOnSlowPath); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 5545 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5546 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5547 | // registers in full width (since the runtime only saves/restores lower part). |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5548 | locations->SetCustomSlowPathCallerSaves( |
| 5549 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5550 | } |
| 5551 | |
| 5552 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5553 | HBasicBlock* block = instruction->GetBlock(); |
| 5554 | if (block->GetLoopInformation() != nullptr) { |
| 5555 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5556 | // The back edge will generate the suspend check. |
| 5557 | return; |
| 5558 | } |
| 5559 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5560 | // The goto will generate the suspend check. |
| 5561 | return; |
| 5562 | } |
| 5563 | GenerateSuspendCheck(instruction, nullptr); |
| 5564 | } |
| 5565 | |
| 5566 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5567 | HBasicBlock* successor) { |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5568 | SuspendCheckSlowPathX86_64* slow_path = |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5569 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 5570 | if (slow_path == nullptr) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5571 | slow_path = |
| 5572 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86_64(instruction, successor); |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5573 | instruction->SetSlowPath(slow_path); |
| 5574 | codegen_->AddSlowPath(slow_path); |
| 5575 | if (successor != nullptr) { |
| 5576 | DCHECK(successor->IsLoopHeader()); |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5577 | } |
| 5578 | } else { |
| 5579 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5580 | } |
| 5581 | |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5582 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64PointerSize>().Int32Value(), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5583 | /* no_rip= */ true), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5584 | Immediate(0)); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5585 | if (successor == nullptr) { |
| 5586 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5587 | __ Bind(slow_path->GetReturnLabel()); |
| 5588 | } else { |
| 5589 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5590 | __ jmp(slow_path->GetEntryLabel()); |
| 5591 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5592 | } |
| 5593 | |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5594 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 5595 | return codegen_->GetAssembler(); |
| 5596 | } |
| 5597 | |
| 5598 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5599 | MoveOperands* move = moves_[index]; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5600 | Location source = move->GetSource(); |
| 5601 | Location destination = move->GetDestination(); |
| 5602 | |
| 5603 | if (source.IsRegister()) { |
| 5604 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5605 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5606 | } else if (destination.IsStackSlot()) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5607 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5608 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5609 | } else { |
| 5610 | DCHECK(destination.IsDoubleStackSlot()); |
| 5611 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5612 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5613 | } |
| 5614 | } else if (source.IsStackSlot()) { |
| 5615 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5616 | __ movl(destination.AsRegister<CpuRegister>(), |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5617 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5618 | } else if (destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5619 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5620 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5621 | } else { |
| 5622 | DCHECK(destination.IsStackSlot()); |
| 5623 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5624 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5625 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5626 | } else if (source.IsDoubleStackSlot()) { |
| 5627 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5628 | __ movq(destination.AsRegister<CpuRegister>(), |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5629 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5630 | } else if (destination.IsFpuRegister()) { |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5631 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5632 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5633 | } else { |
| Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5634 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5635 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5636 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5637 | } |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5638 | } else if (source.IsSIMDStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5639 | if (destination.IsFpuRegister()) { |
| 5640 | __ movups(destination.AsFpuRegister<XmmRegister>(), |
| 5641 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5642 | } else { |
| 5643 | DCHECK(destination.IsSIMDStackSlot()); |
| 5644 | size_t high = kX86_64WordSize; |
| 5645 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5646 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5647 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex() + high)); |
| 5648 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex() + high), CpuRegister(TMP)); |
| 5649 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5650 | } else if (source.IsConstant()) { |
| 5651 | HConstant* constant = source.GetConstant(); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5652 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5653 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5654 | if (destination.IsRegister()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5655 | if (value == 0) { |
| 5656 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5657 | } else { |
| 5658 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5659 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5660 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5661 | DCHECK(destination.IsStackSlot()) << destination; |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5662 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5663 | } |
| 5664 | } else if (constant->IsLongConstant()) { |
| 5665 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5666 | if (destination.IsRegister()) { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5667 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5668 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5669 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5670 | codegen_->Store64BitValueToStack(destination, value); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5671 | } |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5672 | } else if (constant->IsFloatConstant()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5673 | float fp_value = constant->AsFloatConstant()->GetValue(); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5674 | if (destination.IsFpuRegister()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5675 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5676 | codegen_->Load32BitValue(dest, fp_value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5677 | } else { |
| 5678 | DCHECK(destination.IsStackSlot()) << destination; |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5679 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5680 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5681 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5682 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5683 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5684 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
| Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5685 | int64_t value = bit_cast<int64_t, double>(fp_value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5686 | if (destination.IsFpuRegister()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5687 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5688 | codegen_->Load64BitValue(dest, fp_value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5689 | } else { |
| 5690 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5691 | codegen_->Store64BitValueToStack(destination, value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5692 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5693 | } |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5694 | } else if (source.IsFpuRegister()) { |
| 5695 | if (destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5696 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5697 | } else if (destination.IsStackSlot()) { |
| 5698 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5699 | source.AsFpuRegister<XmmRegister>()); |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5700 | } else if (destination.IsDoubleStackSlot()) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5701 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5702 | source.AsFpuRegister<XmmRegister>()); |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5703 | } else { |
| 5704 | DCHECK(destination.IsSIMDStackSlot()); |
| 5705 | __ movups(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 5706 | source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5707 | } |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5708 | } |
| 5709 | } |
| 5710 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5711 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5712 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5713 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 5714 | __ movl(reg, CpuRegister(TMP)); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5715 | } |
| 5716 | |
| Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5717 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg1, CpuRegister reg2) { |
| 5718 | __ movq(CpuRegister(TMP), reg1); |
| 5719 | __ movq(reg1, reg2); |
| 5720 | __ movq(reg2, CpuRegister(TMP)); |
| 5721 | } |
| 5722 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5723 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 5724 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5725 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 5726 | __ movq(reg, CpuRegister(TMP)); |
| 5727 | } |
| 5728 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5729 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 5730 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5731 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 5732 | __ movd(reg, CpuRegister(TMP)); |
| 5733 | } |
| 5734 | |
| 5735 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 5736 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5737 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 5738 | __ movd(reg, CpuRegister(TMP)); |
| 5739 | } |
| 5740 | |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5741 | void ParallelMoveResolverX86_64::Exchange128(XmmRegister reg, int mem) { |
| 5742 | size_t extra_slot = 2 * kX86_64WordSize; |
| 5743 | __ subq(CpuRegister(RSP), Immediate(extra_slot)); |
| 5744 | __ movups(Address(CpuRegister(RSP), 0), XmmRegister(reg)); |
| 5745 | ExchangeMemory64(0, mem + extra_slot, 2); |
| 5746 | __ movups(XmmRegister(reg), Address(CpuRegister(RSP), 0)); |
| 5747 | __ addq(CpuRegister(RSP), Immediate(extra_slot)); |
| 5748 | } |
| 5749 | |
| 5750 | void ParallelMoveResolverX86_64::ExchangeMemory32(int mem1, int mem2) { |
| 5751 | ScratchRegisterScope ensure_scratch( |
| 5752 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5753 | |
| 5754 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5755 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5756 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 5757 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5758 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5759 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5760 | CpuRegister(ensure_scratch.GetRegister())); |
| 5761 | } |
| 5762 | |
| 5763 | void ParallelMoveResolverX86_64::ExchangeMemory64(int mem1, int mem2, int num_of_qwords) { |
| 5764 | ScratchRegisterScope ensure_scratch( |
| 5765 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5766 | |
| 5767 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5768 | |
| 5769 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. |
| 5770 | for (int i = 0; i < num_of_qwords; i++) { |
| 5771 | __ movq(CpuRegister(TMP), |
| 5772 | Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5773 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 5774 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5775 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), |
| 5776 | CpuRegister(TMP)); |
| 5777 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5778 | CpuRegister(ensure_scratch.GetRegister())); |
| 5779 | stack_offset += kX86_64WordSize; |
| 5780 | } |
| 5781 | } |
| 5782 | |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5783 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5784 | MoveOperands* move = moves_[index]; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5785 | Location source = move->GetSource(); |
| 5786 | Location destination = move->GetDestination(); |
| 5787 | |
| 5788 | if (source.IsRegister() && destination.IsRegister()) { |
| Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5789 | Exchange64(source.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5790 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5791 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5792 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5793 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5794 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5795 | ExchangeMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5796 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5797 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5798 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5799 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5800 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5801 | ExchangeMemory64(destination.GetStackIndex(), source.GetStackIndex(), 1); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5802 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5803 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 5804 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5805 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5806 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5807 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5808 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5809 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5810 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5811 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5812 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5813 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5814 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { |
| 5815 | ExchangeMemory64(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| 5816 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { |
| 5817 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5818 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { |
| 5819 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5820 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5821 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5822 | } |
| 5823 | } |
| 5824 | |
| 5825 | |
| 5826 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 5827 | __ pushq(CpuRegister(reg)); |
| 5828 | } |
| 5829 | |
| 5830 | |
| 5831 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 5832 | __ popq(CpuRegister(reg)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5833 | } |
| 5834 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5835 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5836 | SlowPathCode* slow_path, CpuRegister class_reg) { |
| Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 5837 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 5838 | const size_t status_byte_offset = |
| 5839 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 5840 | constexpr uint32_t shifted_initialized_value = |
| 5841 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
| 5842 | |
| 5843 | __ cmpb(Address(class_reg, status_byte_offset), Immediate(shifted_initialized_value)); |
| Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 5844 | __ j(kBelow, slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5845 | __ Bind(slow_path->GetExitLabel()); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5846 | // No need for memory fence, thanks to the x86-64 memory model. |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5847 | } |
| 5848 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 5849 | void InstructionCodeGeneratorX86_64::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, |
| 5850 | CpuRegister temp) { |
| 5851 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 5852 | uint32_t mask = check->GetBitstringMask(); |
| 5853 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 5854 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 5855 | |
| 5856 | if (mask_bits == 16u) { |
| 5857 | // Compare the bitstring in memory. |
| 5858 | __ cmpw(Address(temp, mirror::Class::StatusOffset()), Immediate(path_to_root)); |
| 5859 | } else { |
| 5860 | // /* uint32_t */ temp = temp->status_ |
| 5861 | __ movl(temp, Address(temp, mirror::Class::StatusOffset())); |
| 5862 | // Compare the bitstring bits using SUB. |
| 5863 | __ subl(temp, Immediate(path_to_root)); |
| 5864 | // Shift out bits that do not contribute to the comparison. |
| 5865 | __ shll(temp, Immediate(32u - mask_bits)); |
| 5866 | } |
| 5867 | } |
| 5868 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5869 | HLoadClass::LoadKind CodeGeneratorX86_64::GetSupportedLoadClassKind( |
| 5870 | HLoadClass::LoadKind desired_class_load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5871 | switch (desired_class_load_kind) { |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5872 | case HLoadClass::LoadKind::kInvalid: |
| 5873 | LOG(FATAL) << "UNREACHABLE"; |
| 5874 | UNREACHABLE(); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5875 | case HLoadClass::LoadKind::kReferrersClass: |
| 5876 | break; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5877 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5878 | case HLoadClass::LoadKind::kBootImageRelRo: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5879 | case HLoadClass::LoadKind::kBssEntry: |
| 5880 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5881 | break; |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5882 | case HLoadClass::LoadKind::kJitBootImageAddress: |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5883 | case HLoadClass::LoadKind::kJitTableAddress: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5884 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5885 | break; |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5886 | case HLoadClass::LoadKind::kRuntimeCall: |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5887 | break; |
| 5888 | } |
| 5889 | return desired_class_load_kind; |
| 5890 | } |
| 5891 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5892 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5893 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5894 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5895 | // Custom calling convention: RAX serves as both input and output. |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5896 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5897 | cls, |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5898 | Location::RegisterLocation(RAX), |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5899 | Location::RegisterLocation(RAX)); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5900 | return; |
| 5901 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5902 | DCHECK(!cls->NeedsAccessCheck()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5903 | |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5904 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5905 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5906 | ? LocationSummary::kCallOnSlowPath |
| 5907 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5908 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5909 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5910 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5911 | } |
| 5912 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5913 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5914 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5915 | } |
| 5916 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5917 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 5918 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5919 | // Rely on the type resolution and/or initialization to save everything. |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 5920 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5921 | } else { |
| 5922 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5923 | } |
| 5924 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5925 | } |
| 5926 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5927 | Label* CodeGeneratorX86_64::NewJitRootClassPatch(const DexFile& dex_file, |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5928 | dex::TypeIndex type_index, |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5929 | Handle<mirror::Class> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5930 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5931 | // Add a patch entry and return the label. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5932 | jit_class_patches_.emplace_back(&dex_file, type_index.index_); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5933 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 5934 | return &info->label; |
| 5935 | } |
| 5936 | |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5937 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5938 | // move. |
| 5939 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5940 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5941 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5942 | codegen_->GenerateLoadClassRuntimeCall(cls); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5943 | return; |
| 5944 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5945 | DCHECK(!cls->NeedsAccessCheck()); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5946 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5947 | LocationSummary* locations = cls->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5948 | Location out_loc = locations->Out(); |
| 5949 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5950 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5951 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5952 | ? kWithoutReadBarrier |
| 5953 | : kCompilerReadBarrierOption; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5954 | bool generate_null_check = false; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5955 | switch (load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5956 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5957 | DCHECK(!cls->CanCallRuntime()); |
| 5958 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5959 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5960 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5961 | GenerateGcRootFieldLoad( |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5962 | cls, |
| 5963 | out_loc, |
| 5964 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5965 | /* fixup_label= */ nullptr, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5966 | read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5967 | break; |
| 5968 | } |
| 5969 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5970 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5971 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5972 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip= */ false)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5973 | codegen_->RecordBootImageTypePatch(cls); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5974 | break; |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5975 | case HLoadClass::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5976 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5977 | __ movl(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip= */ false)); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5978 | codegen_->RecordBootImageRelRoPatch(codegen_->GetBootImageOffset(cls)); |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5979 | break; |
| 5980 | } |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5981 | case HLoadClass::LoadKind::kBssEntry: { |
| 5982 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5983 | /* no_rip= */ false); |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5984 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 5985 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
| 5986 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 5987 | // No need for memory fence, thanks to the x86-64 memory model. |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5988 | generate_null_check = true; |
| 5989 | break; |
| 5990 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5991 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 5992 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 5993 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 5994 | DCHECK_NE(address, 0u); |
| 5995 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
| 5996 | break; |
| 5997 | } |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5998 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5999 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6000 | /* no_rip= */ true); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6001 | Label* fixup_label = |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6002 | codegen_->NewJitRootClassPatch(cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6003 | // /* GcRoot<mirror::Class> */ out = *address |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6004 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6005 | break; |
| 6006 | } |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6007 | default: |
| 6008 | LOG(FATAL) << "Unexpected load kind: " << cls->GetLoadKind(); |
| 6009 | UNREACHABLE(); |
| 6010 | } |
| 6011 | |
| 6012 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6013 | DCHECK(cls->CanCallRuntime()); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6014 | SlowPathCode* slow_path = |
| 6015 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86_64(cls, cls); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6016 | codegen_->AddSlowPath(slow_path); |
| 6017 | if (generate_null_check) { |
| 6018 | __ testl(out, out); |
| 6019 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6020 | } |
| 6021 | if (cls->MustGenerateClinitCheck()) { |
| 6022 | GenerateClassInitializationCheck(slow_path, out); |
| 6023 | } else { |
| 6024 | __ Bind(slow_path->GetExitLabel()); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6025 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6026 | } |
| 6027 | } |
| 6028 | |
| 6029 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 6030 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6031 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6032 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6033 | if (check->HasUses()) { |
| 6034 | locations->SetOut(Location::SameAsFirstInput()); |
| 6035 | } |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6036 | // Rely on the type initialization to save everything we need. |
| 6037 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6038 | } |
| 6039 | |
| Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6040 | void LocationsBuilderX86_64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6041 | // Custom calling convention: RAX serves as both input and output. |
| 6042 | Location location = Location::RegisterLocation(RAX); |
| 6043 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 6044 | } |
| 6045 | |
| 6046 | void InstructionCodeGeneratorX86_64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6047 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 6048 | } |
| 6049 | |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6050 | void LocationsBuilderX86_64::VisitLoadMethodType(HLoadMethodType* load) { |
| 6051 | // Custom calling convention: RAX serves as both input and output. |
| 6052 | Location location = Location::RegisterLocation(RAX); |
| 6053 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 6054 | } |
| 6055 | |
| 6056 | void InstructionCodeGeneratorX86_64::VisitLoadMethodType(HLoadMethodType* load) { |
| 6057 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 6058 | } |
| 6059 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6060 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6061 | // We assume the class to not be null. |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6062 | SlowPathCode* slow_path = |
| 6063 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86_64(check->GetLoadClass(), check); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6064 | codegen_->AddSlowPath(slow_path); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6065 | GenerateClassInitializationCheck(slow_path, |
| 6066 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6067 | } |
| 6068 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6069 | HLoadString::LoadKind CodeGeneratorX86_64::GetSupportedLoadStringKind( |
| 6070 | HLoadString::LoadKind desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6071 | switch (desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6072 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6073 | case HLoadString::LoadKind::kBootImageRelRo: |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6074 | case HLoadString::LoadKind::kBssEntry: |
| Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6075 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6076 | break; |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6077 | case HLoadString::LoadKind::kJitBootImageAddress: |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6078 | case HLoadString::LoadKind::kJitTableAddress: |
| 6079 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6080 | break; |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6081 | case HLoadString::LoadKind::kRuntimeCall: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6082 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6083 | } |
| 6084 | return desired_string_load_kind; |
| 6085 | } |
| 6086 | |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6087 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6088 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6089 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6090 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
| Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 6091 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 6092 | } else { |
| 6093 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6094 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 6095 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6096 | // Rely on the pResolveString to save everything. |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6097 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6098 | } else { |
| 6099 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6100 | } |
| 6101 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6102 | } |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6103 | } |
| 6104 | |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6105 | Label* CodeGeneratorX86_64::NewJitRootStringPatch(const DexFile& dex_file, |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6106 | dex::StringIndex string_index, |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6107 | Handle<mirror::String> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6108 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6109 | // Add a patch entry and return the label. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6110 | jit_string_patches_.emplace_back(&dex_file, string_index.index_); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6111 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6112 | return &info->label; |
| 6113 | } |
| 6114 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6115 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6116 | // move. |
| 6117 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
| Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6118 | LocationSummary* locations = load->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6119 | Location out_loc = locations->Out(); |
| 6120 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6121 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6122 | switch (load->GetLoadKind()) { |
| 6123 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6124 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6125 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip= */ false)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6126 | codegen_->RecordBootImageStringPatch(load); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6127 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6128 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6129 | case HLoadString::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6130 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6131 | __ movl(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip= */ false)); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6132 | codegen_->RecordBootImageRelRoPatch(codegen_->GetBootImageOffset(load)); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6133 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6134 | } |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6135 | case HLoadString::LoadKind::kBssEntry: { |
| 6136 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6137 | /* no_rip= */ false); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6138 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
| 6139 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6140 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 6141 | // No need for memory fence, thanks to the x86-64 memory model. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6142 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86_64(load); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6143 | codegen_->AddSlowPath(slow_path); |
| 6144 | __ testl(out, out); |
| 6145 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6146 | __ Bind(slow_path->GetExitLabel()); |
| 6147 | return; |
| 6148 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6149 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 6150 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 6151 | DCHECK_NE(address, 0u); |
| 6152 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
| 6153 | return; |
| 6154 | } |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6155 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6156 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6157 | /* no_rip= */ true); |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6158 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
| 6159 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6160 | // /* GcRoot<mirror::String> */ out = *address |
| 6161 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6162 | return; |
| 6163 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6164 | default: |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6165 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6166 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6167 | |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6168 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6169 | // Custom calling convention: RAX serves as both input and output. |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6170 | __ movl(CpuRegister(RAX), Immediate(load->GetStringIndex().index_)); |
| Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 6171 | codegen_->InvokeRuntime(kQuickResolveString, |
| 6172 | load, |
| 6173 | load->GetDexPc()); |
| 6174 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6175 | } |
| 6176 | |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6177 | static Address GetExceptionTlsAddress() { |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6178 | return Address::Absolute(Thread::ExceptionOffset<kX86_64PointerSize>().Int32Value(), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6179 | /* no_rip= */ true); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6180 | } |
| 6181 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6182 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 6183 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6184 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6185 | locations->SetOut(Location::RequiresRegister()); |
| 6186 | } |
| 6187 | |
| 6188 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6189 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 6190 | } |
| 6191 | |
| 6192 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6193 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6194 | } |
| 6195 | |
| 6196 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6197 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6198 | } |
| 6199 | |
| 6200 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6201 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6202 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6203 | InvokeRuntimeCallingConvention calling_convention; |
| 6204 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6205 | } |
| 6206 | |
| 6207 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6208 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6209 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6210 | } |
| 6211 | |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6212 | // Temp is used for read barrier. |
| 6213 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6214 | if (kEmitCompilerReadBarrier && |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6215 | !kUseBakerReadBarrier && |
| 6216 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6217 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6218 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6219 | return 1; |
| 6220 | } |
| 6221 | return 0; |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6222 | } |
| 6223 | |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6224 | // Interface case has 2 temps, one for holding the number of interfaces, one for the current |
| 6225 | // interface pointer, the current interface is compared in memory. |
| 6226 | // The other checks have one temp for loading the object's class. |
| 6227 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6228 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6229 | return 2; |
| 6230 | } |
| 6231 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6232 | } |
| 6233 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6234 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6235 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6236 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6237 | bool baker_read_barrier_slow_path = false; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6238 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6239 | case TypeCheckKind::kExactCheck: |
| 6240 | case TypeCheckKind::kAbstractClassCheck: |
| 6241 | case TypeCheckKind::kClassHierarchyCheck: |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6242 | case TypeCheckKind::kArrayObjectCheck: { |
| 6243 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 6244 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 6245 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6246 | break; |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6247 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6248 | case TypeCheckKind::kArrayCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6249 | case TypeCheckKind::kUnresolvedCheck: |
| 6250 | case TypeCheckKind::kInterfaceCheck: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6251 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6252 | break; |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6253 | case TypeCheckKind::kBitstringCheck: |
| 6254 | break; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6255 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6256 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6257 | LocationSummary* locations = |
| 6258 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6259 | if (baker_read_barrier_slow_path) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6260 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6261 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6262 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6263 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 6264 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 6265 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 6266 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 6267 | } else { |
| 6268 | locations->SetInAt(1, Location::Any()); |
| 6269 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6270 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 6271 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6272 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6273 | } |
| 6274 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6275 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6276 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6277 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6278 | Location obj_loc = locations->InAt(0); |
| 6279 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6280 | Location cls = locations->InAt(1); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6281 | Location out_loc = locations->Out(); |
| 6282 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6283 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6284 | DCHECK_LE(num_temps, 1u); |
| 6285 | Location maybe_temp_loc = (num_temps >= 1u) ? locations->GetTemp(0) : Location::NoLocation(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6286 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6287 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6288 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6289 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6290 | SlowPathCode* slow_path = nullptr; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6291 | NearLabel done, zero; |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6292 | |
| 6293 | // Return 0 if `obj` is null. |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6294 | // Avoid null check if we know obj is not null. |
| 6295 | if (instruction->MustDoNullCheck()) { |
| 6296 | __ testl(obj, obj); |
| 6297 | __ j(kEqual, &zero); |
| 6298 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6299 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6300 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6301 | case TypeCheckKind::kExactCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6302 | ReadBarrierOption read_barrier_option = |
| 6303 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6304 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6305 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6306 | out_loc, |
| 6307 | obj_loc, |
| 6308 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6309 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6310 | if (cls.IsRegister()) { |
| 6311 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6312 | } else { |
| 6313 | DCHECK(cls.IsStackSlot()) << cls; |
| 6314 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6315 | } |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6316 | if (zero.IsLinked()) { |
| 6317 | // Classes must be equal for the instanceof to succeed. |
| 6318 | __ j(kNotEqual, &zero); |
| 6319 | __ movl(out, Immediate(1)); |
| 6320 | __ jmp(&done); |
| 6321 | } else { |
| 6322 | __ setcc(kEqual, out); |
| 6323 | // setcc only sets the low byte. |
| 6324 | __ andl(out, Immediate(1)); |
| 6325 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6326 | break; |
| 6327 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6328 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6329 | case TypeCheckKind::kAbstractClassCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6330 | ReadBarrierOption read_barrier_option = |
| 6331 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6332 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6333 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6334 | out_loc, |
| 6335 | obj_loc, |
| 6336 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6337 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6338 | // If the class is abstract, we eagerly fetch the super class of the |
| 6339 | // object to avoid doing a comparison we know will fail. |
| 6340 | NearLabel loop, success; |
| 6341 | __ Bind(&loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6342 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6343 | GenerateReferenceLoadOneRegister(instruction, |
| 6344 | out_loc, |
| 6345 | super_offset, |
| 6346 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6347 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6348 | __ testl(out, out); |
| 6349 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6350 | __ j(kEqual, &done); |
| 6351 | if (cls.IsRegister()) { |
| 6352 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6353 | } else { |
| 6354 | DCHECK(cls.IsStackSlot()) << cls; |
| 6355 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6356 | } |
| 6357 | __ j(kNotEqual, &loop); |
| 6358 | __ movl(out, Immediate(1)); |
| 6359 | if (zero.IsLinked()) { |
| 6360 | __ jmp(&done); |
| 6361 | } |
| 6362 | break; |
| 6363 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6364 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6365 | case TypeCheckKind::kClassHierarchyCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6366 | ReadBarrierOption read_barrier_option = |
| 6367 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6368 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6369 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6370 | out_loc, |
| 6371 | obj_loc, |
| 6372 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6373 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6374 | // Walk over the class hierarchy to find a match. |
| 6375 | NearLabel loop, success; |
| 6376 | __ Bind(&loop); |
| 6377 | if (cls.IsRegister()) { |
| 6378 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6379 | } else { |
| 6380 | DCHECK(cls.IsStackSlot()) << cls; |
| 6381 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6382 | } |
| 6383 | __ j(kEqual, &success); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6384 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6385 | GenerateReferenceLoadOneRegister(instruction, |
| 6386 | out_loc, |
| 6387 | super_offset, |
| 6388 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6389 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6390 | __ testl(out, out); |
| 6391 | __ j(kNotEqual, &loop); |
| 6392 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6393 | __ jmp(&done); |
| 6394 | __ Bind(&success); |
| 6395 | __ movl(out, Immediate(1)); |
| 6396 | if (zero.IsLinked()) { |
| 6397 | __ jmp(&done); |
| 6398 | } |
| 6399 | break; |
| 6400 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6401 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6402 | case TypeCheckKind::kArrayObjectCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6403 | ReadBarrierOption read_barrier_option = |
| 6404 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6405 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6406 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6407 | out_loc, |
| 6408 | obj_loc, |
| 6409 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6410 | read_barrier_option); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6411 | // Do an exact check. |
| 6412 | NearLabel exact_check; |
| 6413 | if (cls.IsRegister()) { |
| 6414 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6415 | } else { |
| 6416 | DCHECK(cls.IsStackSlot()) << cls; |
| 6417 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6418 | } |
| 6419 | __ j(kEqual, &exact_check); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6420 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6421 | // /* HeapReference<Class> */ out = out->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6422 | GenerateReferenceLoadOneRegister(instruction, |
| 6423 | out_loc, |
| 6424 | component_offset, |
| 6425 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6426 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6427 | __ testl(out, out); |
| 6428 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6429 | __ j(kEqual, &done); |
| 6430 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6431 | __ j(kNotEqual, &zero); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6432 | __ Bind(&exact_check); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6433 | __ movl(out, Immediate(1)); |
| 6434 | __ jmp(&done); |
| 6435 | break; |
| 6436 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6437 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6438 | case TypeCheckKind::kArrayCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6439 | // No read barrier since the slow path will retry upon failure. |
| 6440 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6441 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6442 | out_loc, |
| 6443 | obj_loc, |
| 6444 | class_offset, |
| 6445 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6446 | if (cls.IsRegister()) { |
| 6447 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6448 | } else { |
| 6449 | DCHECK(cls.IsStackSlot()) << cls; |
| 6450 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6451 | } |
| 6452 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6453 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6454 | instruction, /* is_fatal= */ false); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6455 | codegen_->AddSlowPath(slow_path); |
| 6456 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6457 | __ movl(out, Immediate(1)); |
| 6458 | if (zero.IsLinked()) { |
| 6459 | __ jmp(&done); |
| 6460 | } |
| 6461 | break; |
| 6462 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6463 | |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6464 | case TypeCheckKind::kUnresolvedCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6465 | case TypeCheckKind::kInterfaceCheck: { |
| 6466 | // Note that we indeed only call on slow path, but we always go |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6467 | // into the slow path for the unresolved and interface check |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6468 | // cases. |
| 6469 | // |
| 6470 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6471 | // entry point without resorting to a type checking slow path |
| 6472 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6473 | // require to assign fixed registers for the inputs of this |
| 6474 | // HInstanceOf instruction (following the runtime calling |
| 6475 | // convention), which might be cluttered by the potential first |
| 6476 | // read barrier emission at the beginning of this method. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6477 | // |
| 6478 | // TODO: Introduce a new runtime entry point taking the object |
| 6479 | // to test (instead of its class) as argument, and let it deal |
| 6480 | // with the read barrier issues. This will let us refactor this |
| 6481 | // case of the `switch` code as it was previously (with a direct |
| 6482 | // call to the runtime not using a type checking slow path). |
| 6483 | // This should also be beneficial for the other cases above. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6484 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6485 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6486 | instruction, /* is_fatal= */ false); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6487 | codegen_->AddSlowPath(slow_path); |
| 6488 | __ jmp(slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6489 | if (zero.IsLinked()) { |
| 6490 | __ jmp(&done); |
| 6491 | } |
| 6492 | break; |
| 6493 | } |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6494 | |
| 6495 | case TypeCheckKind::kBitstringCheck: { |
| 6496 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6497 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6498 | out_loc, |
| 6499 | obj_loc, |
| 6500 | class_offset, |
| 6501 | kWithoutReadBarrier); |
| 6502 | |
| 6503 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 6504 | if (zero.IsLinked()) { |
| 6505 | __ j(kNotEqual, &zero); |
| 6506 | __ movl(out, Immediate(1)); |
| 6507 | __ jmp(&done); |
| 6508 | } else { |
| 6509 | __ setcc(kEqual, out); |
| 6510 | // setcc only sets the low byte. |
| 6511 | __ andl(out, Immediate(1)); |
| 6512 | } |
| 6513 | break; |
| 6514 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6515 | } |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6516 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6517 | if (zero.IsLinked()) { |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6518 | __ Bind(&zero); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6519 | __ xorl(out, out); |
| 6520 | } |
| 6521 | |
| 6522 | if (done.IsLinked()) { |
| 6523 | __ Bind(&done); |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6524 | } |
| 6525 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6526 | if (slow_path != nullptr) { |
| 6527 | __ Bind(slow_path->GetExitLabel()); |
| 6528 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6529 | } |
| 6530 | |
| Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6531 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
| Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6532 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6533 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6534 | LocationSummary* locations = |
| 6535 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6536 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6537 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6538 | // Require a register for the interface check since there is a loop that compares the class to |
| 6539 | // a memory address. |
| 6540 | locations->SetInAt(1, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6541 | } else if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 6542 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 6543 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 6544 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6545 | } else { |
| 6546 | locations->SetInAt(1, Location::Any()); |
| 6547 | } |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6548 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathX86. |
| 6549 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6550 | } |
| 6551 | |
| 6552 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6553 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6554 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6555 | Location obj_loc = locations->InAt(0); |
| 6556 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6557 | Location cls = locations->InAt(1); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6558 | Location temp_loc = locations->GetTemp(0); |
| 6559 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6560 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6561 | DCHECK_GE(num_temps, 1u); |
| 6562 | DCHECK_LE(num_temps, 2u); |
| 6563 | Location maybe_temp2_loc = (num_temps >= 2u) ? locations->GetTemp(1) : Location::NoLocation(); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6564 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6565 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6566 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6567 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6568 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6569 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6570 | const uint32_t object_array_data_offset = |
| 6571 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6572 | |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6573 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6574 | SlowPathCode* type_check_slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6575 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
| 6576 | instruction, is_type_check_slow_path_fatal); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6577 | codegen_->AddSlowPath(type_check_slow_path); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6578 | |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6579 | |
| 6580 | NearLabel done; |
| 6581 | // Avoid null check if we know obj is not null. |
| 6582 | if (instruction->MustDoNullCheck()) { |
| 6583 | __ testl(obj, obj); |
| 6584 | __ j(kEqual, &done); |
| 6585 | } |
| 6586 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6587 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6588 | case TypeCheckKind::kExactCheck: |
| 6589 | case TypeCheckKind::kArrayCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6590 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6591 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6592 | temp_loc, |
| 6593 | obj_loc, |
| 6594 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6595 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6596 | if (cls.IsRegister()) { |
| 6597 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6598 | } else { |
| 6599 | DCHECK(cls.IsStackSlot()) << cls; |
| 6600 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6601 | } |
| 6602 | // Jump to slow path for throwing the exception or doing a |
| 6603 | // more involved array check. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6604 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6605 | break; |
| 6606 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6607 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6608 | case TypeCheckKind::kAbstractClassCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6609 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6610 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6611 | temp_loc, |
| 6612 | obj_loc, |
| 6613 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6614 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6615 | // If the class is abstract, we eagerly fetch the super class of the |
| 6616 | // object to avoid doing a comparison we know will fail. |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6617 | NearLabel loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6618 | __ Bind(&loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6619 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6620 | GenerateReferenceLoadOneRegister(instruction, |
| 6621 | temp_loc, |
| 6622 | super_offset, |
| 6623 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6624 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6625 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6626 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6627 | // exception. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6628 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6629 | // Otherwise, compare the classes. |
| 6630 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6631 | if (cls.IsRegister()) { |
| 6632 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6633 | } else { |
| 6634 | DCHECK(cls.IsStackSlot()) << cls; |
| 6635 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6636 | } |
| 6637 | __ j(kNotEqual, &loop); |
| 6638 | break; |
| 6639 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6640 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6641 | case TypeCheckKind::kClassHierarchyCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6642 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6643 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6644 | temp_loc, |
| 6645 | obj_loc, |
| 6646 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6647 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6648 | // Walk over the class hierarchy to find a match. |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6649 | NearLabel loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6650 | __ Bind(&loop); |
| 6651 | if (cls.IsRegister()) { |
| 6652 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6653 | } else { |
| 6654 | DCHECK(cls.IsStackSlot()) << cls; |
| 6655 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6656 | } |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6657 | __ j(kEqual, &done); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6658 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6659 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6660 | GenerateReferenceLoadOneRegister(instruction, |
| 6661 | temp_loc, |
| 6662 | super_offset, |
| 6663 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6664 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6665 | |
| 6666 | // If the class reference currently in `temp` is not null, jump |
| 6667 | // back at the beginning of the loop. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6668 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6669 | __ j(kNotZero, &loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6670 | // Otherwise, jump to the slow path to throw the exception. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6671 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6672 | break; |
| 6673 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6674 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6675 | case TypeCheckKind::kArrayObjectCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6676 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6677 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6678 | temp_loc, |
| 6679 | obj_loc, |
| 6680 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6681 | kWithoutReadBarrier); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6682 | // Do an exact check. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6683 | NearLabel check_non_primitive_component_type; |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6684 | if (cls.IsRegister()) { |
| 6685 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6686 | } else { |
| 6687 | DCHECK(cls.IsStackSlot()) << cls; |
| 6688 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6689 | } |
| 6690 | __ j(kEqual, &done); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6691 | |
| 6692 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6693 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6694 | GenerateReferenceLoadOneRegister(instruction, |
| 6695 | temp_loc, |
| 6696 | component_offset, |
| 6697 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6698 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6699 | |
| 6700 | // If the component type is not null (i.e. the object is indeed |
| 6701 | // an array), jump to label `check_non_primitive_component_type` |
| 6702 | // to further check that this component type is not a primitive |
| 6703 | // type. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6704 | __ testl(temp, temp); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6705 | // Otherwise, jump to the slow path to throw the exception. |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6706 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6707 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6708 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6709 | break; |
| 6710 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6711 | |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6712 | case TypeCheckKind::kUnresolvedCheck: { |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6713 | // We always go into the type check slow path for the unresolved case. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6714 | // |
| 6715 | // We cannot directly call the CheckCast runtime entry point |
| 6716 | // without resorting to a type checking slow path here (i.e. by |
| 6717 | // calling InvokeRuntime directly), as it would require to |
| 6718 | // assign fixed registers for the inputs of this HInstanceOf |
| 6719 | // instruction (following the runtime calling convention), which |
| 6720 | // might be cluttered by the potential first read barrier |
| 6721 | // emission at the beginning of this method. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6722 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6723 | break; |
| 6724 | } |
| 6725 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6726 | case TypeCheckKind::kInterfaceCheck: { |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6727 | // Fast path for the interface check. Try to avoid read barriers to improve the fast path. |
| 6728 | // We can not get false positives by doing this. |
| 6729 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6730 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6731 | temp_loc, |
| 6732 | obj_loc, |
| 6733 | class_offset, |
| 6734 | kWithoutReadBarrier); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6735 | |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6736 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6737 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6738 | temp_loc, |
| 6739 | temp_loc, |
| 6740 | iftable_offset, |
| 6741 | kWithoutReadBarrier); |
| 6742 | // Iftable is never null. |
| 6743 | __ movl(maybe_temp2_loc.AsRegister<CpuRegister>(), Address(temp, array_length_offset)); |
| 6744 | // Maybe poison the `cls` for direct comparison with memory. |
| 6745 | __ MaybePoisonHeapReference(cls.AsRegister<CpuRegister>()); |
| 6746 | // Loop through the iftable and check if any class matches. |
| 6747 | NearLabel start_loop; |
| 6748 | __ Bind(&start_loop); |
| 6749 | // Need to subtract first to handle the empty array case. |
| 6750 | __ subl(maybe_temp2_loc.AsRegister<CpuRegister>(), Immediate(2)); |
| 6751 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 6752 | // Go to next interface if the classes do not match. |
| 6753 | __ cmpl(cls.AsRegister<CpuRegister>(), |
| 6754 | CodeGeneratorX86_64::ArrayAddress(temp, |
| 6755 | maybe_temp2_loc, |
| 6756 | TIMES_4, |
| 6757 | object_array_data_offset)); |
| 6758 | __ j(kNotEqual, &start_loop); // Return if same class. |
| 6759 | // If `cls` was poisoned above, unpoison it. |
| 6760 | __ MaybeUnpoisonHeapReference(cls.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6761 | break; |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6762 | } |
| 6763 | |
| 6764 | case TypeCheckKind::kBitstringCheck: { |
| 6765 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6766 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6767 | temp_loc, |
| 6768 | obj_loc, |
| 6769 | class_offset, |
| 6770 | kWithoutReadBarrier); |
| 6771 | |
| 6772 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 6773 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| 6774 | break; |
| 6775 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6776 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6777 | |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6778 | if (done.IsLinked()) { |
| 6779 | __ Bind(&done); |
| 6780 | } |
| 6781 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6782 | __ Bind(type_check_slow_path->GetExitLabel()); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6783 | } |
| 6784 | |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6785 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6786 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6787 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6788 | InvokeRuntimeCallingConvention calling_convention; |
| 6789 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6790 | } |
| 6791 | |
| 6792 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6793 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6794 | instruction, |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6795 | instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6796 | if (instruction->IsEnter()) { |
| 6797 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6798 | } else { |
| 6799 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6800 | } |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6801 | } |
| 6802 | |
| Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 6803 | void LocationsBuilderX86_64::VisitX86AndNot(HX86AndNot* instruction) { |
| 6804 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 6805 | DCHECK(DataType::IsIntOrLongType(instruction->GetType())) << instruction->GetType(); |
| 6806 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 6807 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6808 | // There is no immediate variant of negated bitwise and in X86. |
| 6809 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6810 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6811 | } |
| 6812 | |
| 6813 | void LocationsBuilderX86_64::VisitX86MaskOrResetLeastSetBit(HX86MaskOrResetLeastSetBit* instruction) { |
| 6814 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 6815 | DCHECK(DataType::IsIntOrLongType(instruction->GetType())) << instruction->GetType(); |
| 6816 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 6817 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6818 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6819 | } |
| 6820 | |
| 6821 | void InstructionCodeGeneratorX86_64::VisitX86AndNot(HX86AndNot* instruction) { |
| 6822 | LocationSummary* locations = instruction->GetLocations(); |
| 6823 | Location first = locations->InAt(0); |
| 6824 | Location second = locations->InAt(1); |
| 6825 | Location dest = locations->Out(); |
| 6826 | __ andn(dest.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 6827 | } |
| 6828 | |
| 6829 | void InstructionCodeGeneratorX86_64::VisitX86MaskOrResetLeastSetBit(HX86MaskOrResetLeastSetBit* instruction) { |
| 6830 | LocationSummary* locations = instruction->GetLocations(); |
| 6831 | Location src = locations->InAt(0); |
| 6832 | Location dest = locations->Out(); |
| 6833 | switch (instruction->GetOpKind()) { |
| 6834 | case HInstruction::kAnd: |
| 6835 | __ blsr(dest.AsRegister<CpuRegister>(), src.AsRegister<CpuRegister>()); |
| 6836 | break; |
| 6837 | case HInstruction::kXor: |
| 6838 | __ blsmsk(dest.AsRegister<CpuRegister>(), src.AsRegister<CpuRegister>()); |
| 6839 | break; |
| 6840 | default: |
| 6841 | LOG(FATAL) << "Unreachable"; |
| 6842 | } |
| 6843 | } |
| 6844 | |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6845 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6846 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6847 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6848 | |
| 6849 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6850 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6851 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6852 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 6853 | || instruction->GetResultType() == DataType::Type::kInt64); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6854 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6855 | locations->SetInAt(1, Location::Any()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6856 | locations->SetOut(Location::SameAsFirstInput()); |
| 6857 | } |
| 6858 | |
| 6859 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 6860 | HandleBitwiseOperation(instruction); |
| 6861 | } |
| 6862 | |
| 6863 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 6864 | HandleBitwiseOperation(instruction); |
| 6865 | } |
| 6866 | |
| 6867 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 6868 | HandleBitwiseOperation(instruction); |
| 6869 | } |
| 6870 | |
| 6871 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6872 | LocationSummary* locations = instruction->GetLocations(); |
| 6873 | Location first = locations->InAt(0); |
| 6874 | Location second = locations->InAt(1); |
| 6875 | DCHECK(first.Equals(locations->Out())); |
| 6876 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6877 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6878 | if (second.IsRegister()) { |
| 6879 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6880 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6881 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6882 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6883 | } else { |
| 6884 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6885 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6886 | } |
| 6887 | } else if (second.IsConstant()) { |
| 6888 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 6889 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6890 | __ andl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6891 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6892 | __ orl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6893 | } else { |
| 6894 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6895 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6896 | } |
| 6897 | } else { |
| 6898 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 6899 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6900 | __ andl(first.AsRegister<CpuRegister>(), address); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6901 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6902 | __ orl(first.AsRegister<CpuRegister>(), address); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6903 | } else { |
| 6904 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6905 | __ xorl(first.AsRegister<CpuRegister>(), address); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6906 | } |
| 6907 | } |
| 6908 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6909 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6910 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 6911 | bool second_is_constant = false; |
| 6912 | int64_t value = 0; |
| 6913 | if (second.IsConstant()) { |
| 6914 | second_is_constant = true; |
| 6915 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6916 | } |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6917 | bool is_int32_value = IsInt<32>(value); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6918 | |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6919 | if (instruction->IsAnd()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6920 | if (second_is_constant) { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6921 | if (is_int32_value) { |
| 6922 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6923 | } else { |
| 6924 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6925 | } |
| 6926 | } else if (second.IsDoubleStackSlot()) { |
| 6927 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6928 | } else { |
| 6929 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 6930 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6931 | } else if (instruction->IsOr()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6932 | if (second_is_constant) { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6933 | if (is_int32_value) { |
| 6934 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6935 | } else { |
| 6936 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6937 | } |
| 6938 | } else if (second.IsDoubleStackSlot()) { |
| 6939 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6940 | } else { |
| 6941 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 6942 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6943 | } else { |
| 6944 | DCHECK(instruction->IsXor()); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6945 | if (second_is_constant) { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6946 | if (is_int32_value) { |
| 6947 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6948 | } else { |
| 6949 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6950 | } |
| 6951 | } else if (second.IsDoubleStackSlot()) { |
| 6952 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6953 | } else { |
| 6954 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 6955 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6956 | } |
| 6957 | } |
| 6958 | } |
| 6959 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6960 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister( |
| 6961 | HInstruction* instruction, |
| 6962 | Location out, |
| 6963 | uint32_t offset, |
| 6964 | Location maybe_temp, |
| 6965 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6966 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6967 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6968 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6969 | if (kUseBakerReadBarrier) { |
| 6970 | // Load with fast path based Baker's read barrier. |
| 6971 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6972 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6973 | instruction, out, out_reg, offset, /* needs_null_check= */ false); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6974 | } else { |
| 6975 | // Load with slow path based read barrier. |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6976 | // Save the value of `out` into `maybe_temp` before overwriting it |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6977 | // in the following move operation, as we will need it for the |
| 6978 | // read barrier below. |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6979 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6980 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6981 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6982 | __ movl(out_reg, Address(out_reg, offset)); |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6983 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6984 | } |
| 6985 | } else { |
| 6986 | // Plain load with no read barrier. |
| 6987 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6988 | __ movl(out_reg, Address(out_reg, offset)); |
| 6989 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6990 | } |
| 6991 | } |
| 6992 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6993 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters( |
| 6994 | HInstruction* instruction, |
| 6995 | Location out, |
| 6996 | Location obj, |
| 6997 | uint32_t offset, |
| 6998 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6999 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 7000 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7001 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7002 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7003 | if (kUseBakerReadBarrier) { |
| 7004 | // Load with fast path based Baker's read barrier. |
| 7005 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7006 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7007 | instruction, out, obj_reg, offset, /* needs_null_check= */ false); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7008 | } else { |
| 7009 | // Load with slow path based read barrier. |
| 7010 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7011 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7012 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7013 | } |
| 7014 | } else { |
| 7015 | // Plain load with no read barrier. |
| 7016 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7017 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7018 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7019 | } |
| 7020 | } |
| 7021 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7022 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad( |
| 7023 | HInstruction* instruction, |
| 7024 | Location root, |
| 7025 | const Address& address, |
| 7026 | Label* fixup_label, |
| 7027 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7028 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7029 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7030 | DCHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7031 | if (kUseBakerReadBarrier) { |
| 7032 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7033 | // Baker's read barrier are used: |
| 7034 | // |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7035 | // root = obj.field; |
| 7036 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7037 | // if (temp != null) { |
| 7038 | // root = temp(root) |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7039 | // } |
| 7040 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7041 | // /* GcRoot<mirror::Object> */ root = *address |
| 7042 | __ movl(root_reg, address); |
| 7043 | if (fixup_label != nullptr) { |
| 7044 | __ Bind(fixup_label); |
| 7045 | } |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7046 | static_assert( |
| 7047 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7048 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7049 | "have different sizes."); |
| 7050 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7051 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7052 | "have different sizes."); |
| 7053 | |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7054 | // Slow path marking the GC root `root`. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7055 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86_64( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7056 | instruction, root, /* unpoison_ref_before_marking= */ false); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7057 | codegen_->AddSlowPath(slow_path); |
| 7058 | |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7059 | // Test the `Thread::Current()->pReadBarrierMarkReg ## root.reg()` entrypoint. |
| 7060 | const int32_t entry_point_offset = |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 7061 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(root.reg()); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7062 | __ gs()->cmpl(Address::Absolute(entry_point_offset, /* no_rip= */ true), Immediate(0)); |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7063 | // The entrypoint is null when the GC is not marking. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7064 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7065 | __ Bind(slow_path->GetExitLabel()); |
| 7066 | } else { |
| 7067 | // GC root loaded through a slow path for read barriers other |
| 7068 | // than Baker's. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7069 | // /* GcRoot<mirror::Object>* */ root = address |
| 7070 | __ leaq(root_reg, address); |
| 7071 | if (fixup_label != nullptr) { |
| 7072 | __ Bind(fixup_label); |
| 7073 | } |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7074 | // /* mirror::Object* */ root = root->Read() |
| 7075 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7076 | } |
| 7077 | } else { |
| 7078 | // Plain GC root load with no read barrier. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7079 | // /* GcRoot<mirror::Object> */ root = *address |
| 7080 | __ movl(root_reg, address); |
| 7081 | if (fixup_label != nullptr) { |
| 7082 | __ Bind(fixup_label); |
| 7083 | } |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7084 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7085 | // do not have to unpoison `root_reg` here. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7086 | } |
| 7087 | } |
| 7088 | |
| 7089 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7090 | Location ref, |
| 7091 | CpuRegister obj, |
| 7092 | uint32_t offset, |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7093 | bool needs_null_check) { |
| 7094 | DCHECK(kEmitCompilerReadBarrier); |
| 7095 | DCHECK(kUseBakerReadBarrier); |
| 7096 | |
| 7097 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7098 | Address src(obj, offset); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7099 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7100 | } |
| 7101 | |
| 7102 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7103 | Location ref, |
| 7104 | CpuRegister obj, |
| 7105 | uint32_t data_offset, |
| 7106 | Location index, |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7107 | bool needs_null_check) { |
| 7108 | DCHECK(kEmitCompilerReadBarrier); |
| 7109 | DCHECK(kUseBakerReadBarrier); |
| 7110 | |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7111 | static_assert( |
| 7112 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7113 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7114 | // /* HeapReference<Object> */ ref = |
| 7115 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7116 | Address src = CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7117 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7118 | } |
| 7119 | |
| 7120 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7121 | Location ref, |
| 7122 | CpuRegister obj, |
| 7123 | const Address& src, |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7124 | bool needs_null_check, |
| 7125 | bool always_update_field, |
| 7126 | CpuRegister* temp1, |
| 7127 | CpuRegister* temp2) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7128 | DCHECK(kEmitCompilerReadBarrier); |
| 7129 | DCHECK(kUseBakerReadBarrier); |
| 7130 | |
| 7131 | // In slow path based read barriers, the read barrier call is |
| 7132 | // inserted after the original load. However, in fast path based |
| 7133 | // Baker's read barriers, we need to perform the load of |
| 7134 | // mirror::Object::monitor_ *before* the original reference load. |
| 7135 | // This load-load ordering is required by the read barrier. |
| 7136 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7137 | // |
| 7138 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7139 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7140 | // HeapReference<Object> ref = *src; // Original reference load. |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7141 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7142 | // if (is_gray) { |
| 7143 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7144 | // } |
| 7145 | // |
| 7146 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7147 | // slightly more complex as: |
| 7148 | // - it implements the load-load fence using a data dependency on |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7149 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7150 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 7151 | // here, which is a no-op thanks to the x86-64 memory model); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7152 | // - it performs additional checks that we do not do here for |
| 7153 | // performance reasons. |
| 7154 | |
| 7155 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7156 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7157 | |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7158 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| Roland Levillain | 14e5a29 | 2018-06-28 12:00:56 +0100 | [diff] [blame] | 7159 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7160 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7161 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7162 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7163 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7164 | |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7165 | // if (rb_state == ReadBarrier::GrayState()) |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7166 | // ref = ReadBarrier::Mark(ref); |
| 7167 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7168 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7169 | if (needs_null_check) { |
| 7170 | MaybeRecordImplicitNullCheck(instruction); |
| 7171 | } |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7172 | |
| 7173 | // Load fence to prevent load-load reordering. |
| 7174 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 7175 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7176 | |
| 7177 | // The actual reference load. |
| 7178 | // /* HeapReference<Object> */ ref = *src |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7179 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7180 | |
| 7181 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7182 | // Slow path marking the object `ref` when it is gray. |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7183 | SlowPathCode* slow_path; |
| 7184 | if (always_update_field) { |
| 7185 | DCHECK(temp1 != nullptr); |
| 7186 | DCHECK(temp2 != nullptr); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7187 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86_64( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7188 | instruction, ref, obj, src, /* unpoison_ref_before_marking= */ true, *temp1, *temp2); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7189 | } else { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7190 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86_64( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7191 | instruction, ref, /* unpoison_ref_before_marking= */ true); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7192 | } |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7193 | AddSlowPath(slow_path); |
| 7194 | |
| 7195 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7196 | __ j(kNotZero, slow_path->GetEntryLabel()); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7197 | |
| 7198 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7199 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7200 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7201 | __ Bind(slow_path->GetExitLabel()); |
| 7202 | } |
| 7203 | |
| 7204 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7205 | Location out, |
| 7206 | Location ref, |
| 7207 | Location obj, |
| 7208 | uint32_t offset, |
| 7209 | Location index) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7210 | DCHECK(kEmitCompilerReadBarrier); |
| 7211 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7212 | // Insert a slow path based read barrier *after* the reference load. |
| 7213 | // |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7214 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7215 | // reference will be carried out by the runtime within the slow |
| 7216 | // path. |
| 7217 | // |
| 7218 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7219 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7220 | // not used by the artReadBarrierSlow entry point. |
| 7221 | // |
| 7222 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7223 | SlowPathCode* slow_path = new (GetScopedAllocator()) |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7224 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 7225 | AddSlowPath(slow_path); |
| 7226 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7227 | __ jmp(slow_path->GetEntryLabel()); |
| 7228 | __ Bind(slow_path->GetExitLabel()); |
| 7229 | } |
| 7230 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7231 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7232 | Location out, |
| 7233 | Location ref, |
| 7234 | Location obj, |
| 7235 | uint32_t offset, |
| 7236 | Location index) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7237 | if (kEmitCompilerReadBarrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7238 | // Baker's read barriers shall be handled by the fast path |
| 7239 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 7240 | DCHECK(!kUseBakerReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7241 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7242 | // by the runtime within the slow path. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7243 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7244 | } else if (kPoisonHeapReferences) { |
| 7245 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 7246 | } |
| 7247 | } |
| 7248 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7249 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7250 | Location out, |
| 7251 | Location root) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7252 | DCHECK(kEmitCompilerReadBarrier); |
| 7253 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7254 | // Insert a slow path based read barrier *after* the GC root load. |
| 7255 | // |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7256 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7257 | // not need to do anything special for this here. |
| 7258 | SlowPathCode* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7259 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7260 | AddSlowPath(slow_path); |
| 7261 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7262 | __ jmp(slow_path->GetEntryLabel()); |
| 7263 | __ Bind(slow_path->GetExitLabel()); |
| 7264 | } |
| 7265 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7266 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7267 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7268 | LOG(FATAL) << "Unreachable"; |
| 7269 | } |
| 7270 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7271 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7272 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7273 | LOG(FATAL) << "Unreachable"; |
| 7274 | } |
| 7275 | |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7276 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7277 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7278 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7279 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7280 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7281 | locations->AddTemp(Location::RequiresRegister()); |
| 7282 | locations->AddTemp(Location::RequiresRegister()); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7283 | } |
| 7284 | |
| 7285 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7286 | int32_t lower_bound = switch_instr->GetStartValue(); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7287 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7288 | LocationSummary* locations = switch_instr->GetLocations(); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7289 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 7290 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 7291 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7292 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7293 | |
| 7294 | // Should we generate smaller inline compare/jumps? |
| 7295 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7296 | // Figure out the correct compare values and jump conditions. |
| 7297 | // Handle the first compare/branch as a special case because it might |
| 7298 | // jump to the default case. |
| 7299 | DCHECK_GT(num_entries, 2u); |
| 7300 | Condition first_condition; |
| 7301 | uint32_t index; |
| 7302 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 7303 | if (lower_bound != 0) { |
| 7304 | first_condition = kLess; |
| 7305 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 7306 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7307 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 7308 | |
| 7309 | index = 1; |
| 7310 | } else { |
| 7311 | // Handle all the compare/jumps below. |
| 7312 | first_condition = kBelow; |
| 7313 | index = 0; |
| 7314 | } |
| 7315 | |
| 7316 | // Handle the rest of the compare/jumps. |
| 7317 | for (; index + 1 < num_entries; index += 2) { |
| 7318 | int32_t compare_to_value = lower_bound + index + 1; |
| 7319 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 7320 | // Jump to successors[index] if value < case_value[index]. |
| 7321 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7322 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7323 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7324 | } |
| 7325 | |
| 7326 | if (index != num_entries) { |
| 7327 | // There are an odd number of entries. Handle the last one. |
| 7328 | DCHECK_EQ(index + 1, num_entries); |
| Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 7329 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7330 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 7331 | } |
| 7332 | |
| 7333 | // And the default for any other value. |
| 7334 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 7335 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 7336 | } |
| 7337 | return; |
| 7338 | } |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7339 | |
| 7340 | // Remove the bias, if needed. |
| 7341 | Register value_reg_out = value_reg_in.AsRegister(); |
| 7342 | if (lower_bound != 0) { |
| 7343 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 7344 | value_reg_out = temp_reg.AsRegister(); |
| 7345 | } |
| 7346 | CpuRegister value_reg(value_reg_out); |
| 7347 | |
| 7348 | // Is the value in range? |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7349 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7350 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7351 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7352 | // We are in the range of the table. |
| 7353 | // Load the address of the jump table in the constant area. |
| 7354 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7355 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7356 | // Load the (signed) offset from the jump table. |
| 7357 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 7358 | |
| 7359 | // Add the offset to the address of the table base. |
| 7360 | __ addq(temp_reg, base_reg); |
| 7361 | |
| 7362 | // And jump. |
| 7363 | __ jmp(temp_reg); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7364 | } |
| 7365 | |
| xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7366 | void LocationsBuilderX86_64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7367 | ATTRIBUTE_UNUSED) { |
| 7368 | LOG(FATAL) << "Unreachable"; |
| 7369 | } |
| 7370 | |
| 7371 | void InstructionCodeGeneratorX86_64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7372 | ATTRIBUTE_UNUSED) { |
| 7373 | LOG(FATAL) << "Unreachable"; |
| 7374 | } |
| 7375 | |
| Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 7376 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 7377 | if (value == 0) { |
| 7378 | __ xorl(dest, dest); |
| 7379 | } else { |
| 7380 | __ movl(dest, Immediate(value)); |
| 7381 | } |
| 7382 | } |
| 7383 | |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 7384 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 7385 | if (value == 0) { |
| Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 7386 | // Clears upper bits too. |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 7387 | __ xorl(dest, dest); |
| Vladimir Marko | ed00978 | 2016-02-22 16:54:39 +0000 | [diff] [blame] | 7388 | } else if (IsUint<32>(value)) { |
| 7389 | // We can use a 32 bit move, as it will zero-extend and is shorter. |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 7390 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 7391 | } else { |
| 7392 | __ movq(dest, Immediate(value)); |
| 7393 | } |
| 7394 | } |
| 7395 | |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 7396 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 7397 | if (value == 0) { |
| 7398 | __ xorps(dest, dest); |
| 7399 | } else { |
| 7400 | __ movss(dest, LiteralInt32Address(value)); |
| 7401 | } |
| 7402 | } |
| 7403 | |
| 7404 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 7405 | if (value == 0) { |
| 7406 | __ xorpd(dest, dest); |
| 7407 | } else { |
| 7408 | __ movsd(dest, LiteralInt64Address(value)); |
| 7409 | } |
| 7410 | } |
| 7411 | |
| 7412 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 7413 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 7414 | } |
| 7415 | |
| 7416 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 7417 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 7418 | } |
| 7419 | |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7420 | void CodeGeneratorX86_64::Compare32BitValue(CpuRegister dest, int32_t value) { |
| 7421 | if (value == 0) { |
| 7422 | __ testl(dest, dest); |
| 7423 | } else { |
| 7424 | __ cmpl(dest, Immediate(value)); |
| 7425 | } |
| 7426 | } |
| 7427 | |
| 7428 | void CodeGeneratorX86_64::Compare64BitValue(CpuRegister dest, int64_t value) { |
| 7429 | if (IsInt<32>(value)) { |
| 7430 | if (value == 0) { |
| 7431 | __ testq(dest, dest); |
| 7432 | } else { |
| 7433 | __ cmpq(dest, Immediate(static_cast<int32_t>(value))); |
| 7434 | } |
| 7435 | } else { |
| 7436 | // Value won't fit in an int. |
| 7437 | __ cmpq(dest, LiteralInt64Address(value)); |
| 7438 | } |
| 7439 | } |
| 7440 | |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7441 | void CodeGeneratorX86_64::GenerateIntCompare(Location lhs, Location rhs) { |
| 7442 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7443 | GenerateIntCompare(lhs_reg, rhs); |
| 7444 | } |
| 7445 | |
| 7446 | void CodeGeneratorX86_64::GenerateIntCompare(CpuRegister lhs, Location rhs) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7447 | if (rhs.IsConstant()) { |
| 7448 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7449 | Compare32BitValue(lhs, value); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7450 | } else if (rhs.IsStackSlot()) { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7451 | __ cmpl(lhs, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7452 | } else { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7453 | __ cmpl(lhs, rhs.AsRegister<CpuRegister>()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7454 | } |
| 7455 | } |
| 7456 | |
| 7457 | void CodeGeneratorX86_64::GenerateLongCompare(Location lhs, Location rhs) { |
| 7458 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| 7459 | if (rhs.IsConstant()) { |
| 7460 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 7461 | Compare64BitValue(lhs_reg, value); |
| 7462 | } else if (rhs.IsDoubleStackSlot()) { |
| 7463 | __ cmpq(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 7464 | } else { |
| 7465 | __ cmpq(lhs_reg, rhs.AsRegister<CpuRegister>()); |
| 7466 | } |
| 7467 | } |
| 7468 | |
| 7469 | Address CodeGeneratorX86_64::ArrayAddress(CpuRegister obj, |
| 7470 | Location index, |
| 7471 | ScaleFactor scale, |
| 7472 | uint32_t data_offset) { |
| 7473 | return index.IsConstant() ? |
| 7474 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 7475 | Address(obj, index.AsRegister<CpuRegister>(), scale, data_offset); |
| 7476 | } |
| 7477 | |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 7478 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 7479 | DCHECK(dest.IsDoubleStackSlot()); |
| 7480 | if (IsInt<32>(value)) { |
| 7481 | // Can move directly as an int32 constant. |
| 7482 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 7483 | Immediate(static_cast<int32_t>(value))); |
| 7484 | } else { |
| 7485 | Load64BitValue(CpuRegister(TMP), value); |
| 7486 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 7487 | } |
| 7488 | } |
| 7489 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7490 | /** |
| 7491 | * Class to handle late fixup of offsets into constant area. |
| 7492 | */ |
| 7493 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 7494 | public: |
| 7495 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 7496 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7497 | |
| 7498 | protected: |
| 7499 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7500 | |
| 7501 | CodeGeneratorX86_64* codegen_; |
| 7502 | |
| 7503 | private: |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7504 | void Process(const MemoryRegion& region, int pos) override { |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7505 | // Patch the correct offset for the instruction. We use the address of the |
| 7506 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 7507 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7508 | int32_t relative_position = constant_offset - pos; |
| 7509 | |
| 7510 | // Patch in the right value. |
| 7511 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7512 | } |
| 7513 | |
| 7514 | // Location in constant area that the fixup refers to. |
| 7515 | size_t offset_into_constant_area_; |
| 7516 | }; |
| 7517 | |
| 7518 | /** |
| 7519 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7520 | * constant area. |
| 7521 | */ |
| 7522 | class JumpTableRIPFixup : public RIPFixup { |
| 7523 | public: |
| 7524 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 7525 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 7526 | |
| 7527 | void CreateJumpTable() { |
| 7528 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 7529 | |
| 7530 | // Ensure that the reference to the jump table has the correct offset. |
| 7531 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7532 | SetOffset(offset_in_constant_table); |
| 7533 | |
| 7534 | // Compute the offset from the start of the function to this jump table. |
| 7535 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 7536 | |
| 7537 | // Populate the jump table with the correct values for the jump table. |
| 7538 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7539 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7540 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7541 | // The value that we want is the target offset - the position of the table. |
| 7542 | for (int32_t i = 0; i < num_entries; i++) { |
| 7543 | HBasicBlock* b = successors[i]; |
| 7544 | Label* l = codegen_->GetLabelOf(b); |
| 7545 | DCHECK(l->IsBound()); |
| 7546 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 7547 | assembler->AppendInt32(offset_to_block); |
| 7548 | } |
| 7549 | } |
| 7550 | |
| 7551 | private: |
| 7552 | const HPackedSwitch* switch_instr_; |
| 7553 | }; |
| 7554 | |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7555 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 7556 | // Generate the constant area if needed. |
| Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7557 | X86_64Assembler* assembler = GetAssembler(); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7558 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7559 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 byte values. |
| Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7560 | assembler->Align(4, 0); |
| 7561 | constant_area_start_ = assembler->CodeSize(); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7562 | |
| 7563 | // Populate any jump tables. |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7564 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7565 | jump_table->CreateJumpTable(); |
| 7566 | } |
| 7567 | |
| 7568 | // And now add the constant area to the generated code. |
| Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7569 | assembler->AddConstantArea(); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7570 | } |
| 7571 | |
| 7572 | // And finish up. |
| 7573 | CodeGenerator::Finalize(allocator); |
| 7574 | } |
| 7575 | |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7576 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7577 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddDouble(v)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7578 | return Address::RIP(fixup); |
| 7579 | } |
| 7580 | |
| 7581 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7582 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddFloat(v)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7583 | return Address::RIP(fixup); |
| 7584 | } |
| 7585 | |
| 7586 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7587 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddInt32(v)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7588 | return Address::RIP(fixup); |
| 7589 | } |
| 7590 | |
| 7591 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7592 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddInt64(v)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7593 | return Address::RIP(fixup); |
| 7594 | } |
| 7595 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7596 | // TODO: trg as memory. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7597 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, DataType::Type type) { |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7598 | if (!trg.IsValid()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7599 | DCHECK_EQ(type, DataType::Type::kVoid); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7600 | return; |
| 7601 | } |
| 7602 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7603 | DCHECK_NE(type, DataType::Type::kVoid); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7604 | |
| 7605 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 7606 | if (trg.Equals(return_loc)) { |
| 7607 | return; |
| 7608 | } |
| 7609 | |
| 7610 | // Let the parallel move resolver take care of all of this. |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7611 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7612 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7613 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7614 | } |
| 7615 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7616 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 7617 | // Create a fixup to be used to create and address the jump table. |
| 7618 | JumpTableRIPFixup* table_fixup = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7619 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7620 | |
| 7621 | // We have to populate the jump tables. |
| 7622 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7623 | return Address::RIP(table_fixup); |
| 7624 | } |
| 7625 | |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 7626 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 7627 | const Address& addr_high, |
| 7628 | int64_t v, |
| 7629 | HInstruction* instruction) { |
| 7630 | if (IsInt<32>(v)) { |
| 7631 | int32_t v_32 = v; |
| 7632 | __ movq(addr_low, Immediate(v_32)); |
| 7633 | MaybeRecordImplicitNullCheck(instruction); |
| 7634 | } else { |
| 7635 | // Didn't fit in a register. Do it in pieces. |
| 7636 | int32_t low_v = Low32Bits(v); |
| 7637 | int32_t high_v = High32Bits(v); |
| 7638 | __ movl(addr_low, Immediate(low_v)); |
| 7639 | MaybeRecordImplicitNullCheck(instruction); |
| 7640 | __ movl(addr_high, Immediate(high_v)); |
| 7641 | } |
| 7642 | } |
| 7643 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7644 | void CodeGeneratorX86_64::PatchJitRootUse(uint8_t* code, |
| 7645 | const uint8_t* roots_data, |
| 7646 | const PatchInfo<Label>& info, |
| 7647 | uint64_t index_in_table) const { |
| 7648 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7649 | uintptr_t address = |
| 7650 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 7651 | using unaligned_uint32_t __attribute__((__aligned__(1))) = uint32_t; |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7652 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7653 | dchecked_integral_cast<uint32_t>(address); |
| 7654 | } |
| 7655 | |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7656 | void CodeGeneratorX86_64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7657 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7658 | StringReference string_reference(info.target_dex_file, dex::StringIndex(info.offset_or_index)); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7659 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7660 | PatchJitRootUse(code, roots_data, info, index_in_table); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7661 | } |
| 7662 | |
| 7663 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7664 | TypeReference type_reference(info.target_dex_file, dex::TypeIndex(info.offset_or_index)); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7665 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7666 | PatchJitRootUse(code, roots_data, info, index_in_table); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7667 | } |
| 7668 | } |
| 7669 | |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame^] | 7670 | bool LocationsBuilderX86_64::CpuHasAvxFeatureFlag() { |
| 7671 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 7672 | } |
| 7673 | |
| 7674 | bool LocationsBuilderX86_64::CpuHasAvx2FeatureFlag() { |
| 7675 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 7676 | } |
| 7677 | |
| 7678 | bool InstructionCodeGeneratorX86_64::CpuHasAvxFeatureFlag() { |
| 7679 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 7680 | } |
| 7681 | |
| 7682 | bool InstructionCodeGeneratorX86_64::CpuHasAvx2FeatureFlag() { |
| 7683 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 7684 | } |
| 7685 | |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7686 | #undef __ |
| 7687 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 7688 | } // namespace x86_64 |
| 7689 | } // namespace art |