blob: 81c6561318531918aa726cf065e918bbadb824e8 [file] [log] [blame]
Andreas Gampe878d58c2015-01-15 23:24:00 -08001/*
2 * Copyright (C) 2015 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#ifndef ART_COMPILER_OPTIMIZING_COMMON_ARM64_H_
18#define ART_COMPILER_OPTIMIZING_COMMON_ARM64_H_
19
Alexandre Rames8626b742015-11-25 16:28:08 +000020#include "code_generator.h"
Anton Kirilov74234da2017-01-13 14:42:47 +000021#include "instruction_simplifier_shared.h"
Andreas Gampe878d58c2015-01-15 23:24:00 -080022#include "locations.h"
23#include "nodes.h"
24#include "utils/arm64/assembler_arm64.h"
Scott Wakeling97c72b72016-06-24 16:19:36 +010025
Artem Serovaf4e42a2016-08-08 15:11:24 +010026// TODO(VIXL): Make VIXL compile with -Wshadow.
27#pragma GCC diagnostic push
28#pragma GCC diagnostic ignored "-Wshadow"
29#include "aarch64/disasm-aarch64.h"
30#include "aarch64/macro-assembler-aarch64.h"
31#include "aarch64/simulator-aarch64.h"
32#pragma GCC diagnostic pop
Andreas Gampe878d58c2015-01-15 23:24:00 -080033
Vladimir Marko0a516052019-10-14 13:00:44 +000034namespace art {
Anton Kirilov74234da2017-01-13 14:42:47 +000035
36using helpers::CanFitInShifterOperand;
37using helpers::HasShifterOperand;
38
Andreas Gampe878d58c2015-01-15 23:24:00 -080039namespace arm64 {
40namespace helpers {
41
Andreas Gampe878d58c2015-01-15 23:24:00 -080042// Convenience helpers to ease conversion to and from VIXL operands.
43static_assert((SP == 31) && (WSP == 31) && (XZR == 32) && (WZR == 32),
44 "Unexpected values for register codes.");
45
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010046inline int VIXLRegCodeFromART(int code) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080047 if (code == SP) {
Scott Wakeling97c72b72016-06-24 16:19:36 +010048 return vixl::aarch64::kSPRegInternalCode;
Andreas Gampe878d58c2015-01-15 23:24:00 -080049 }
50 if (code == XZR) {
Scott Wakeling97c72b72016-06-24 16:19:36 +010051 return vixl::aarch64::kZeroRegCode;
Andreas Gampe878d58c2015-01-15 23:24:00 -080052 }
53 return code;
54}
55
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010056inline int ARTRegCodeFromVIXL(int code) {
Scott Wakeling97c72b72016-06-24 16:19:36 +010057 if (code == vixl::aarch64::kSPRegInternalCode) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080058 return SP;
59 }
Scott Wakeling97c72b72016-06-24 16:19:36 +010060 if (code == vixl::aarch64::kZeroRegCode) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080061 return XZR;
62 }
63 return code;
64}
65
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010066inline vixl::aarch64::Register XRegisterFrom(Location location) {
Roland Levillain3a448e42016-04-01 18:37:46 +010067 DCHECK(location.IsRegister()) << location;
Artem Serova07de552020-11-01 22:42:43 +000068 return vixl::aarch64::XRegister(VIXLRegCodeFromART(location.reg()));
Andreas Gampe878d58c2015-01-15 23:24:00 -080069}
70
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010071inline vixl::aarch64::Register WRegisterFrom(Location location) {
Roland Levillain3a448e42016-04-01 18:37:46 +010072 DCHECK(location.IsRegister()) << location;
Artem Serova07de552020-11-01 22:42:43 +000073 return vixl::aarch64::WRegister(VIXLRegCodeFromART(location.reg()));
Andreas Gampe878d58c2015-01-15 23:24:00 -080074}
75
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010076inline vixl::aarch64::Register RegisterFrom(Location location, DataType::Type type) {
77 DCHECK(type != DataType::Type::kVoid && !DataType::IsFloatingPointType(type)) << type;
78 return type == DataType::Type::kInt64 ? XRegisterFrom(location) : WRegisterFrom(location);
Andreas Gampe878d58c2015-01-15 23:24:00 -080079}
80
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010081inline vixl::aarch64::Register OutputRegister(HInstruction* instr) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080082 return RegisterFrom(instr->GetLocations()->Out(), instr->GetType());
83}
84
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010085inline vixl::aarch64::Register InputRegisterAt(HInstruction* instr, int input_index) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080086 return RegisterFrom(instr->GetLocations()->InAt(input_index),
87 instr->InputAt(input_index)->GetType());
88}
89
Evgeny Astigeevich7d48dcd2019-10-16 12:46:28 +010090inline vixl::aarch64::VRegister DRegisterFrom(Location location) {
Roland Levillain3a448e42016-04-01 18:37:46 +010091 DCHECK(location.IsFpuRegister()) << location;
Artem Serova07de552020-11-01 22:42:43 +000092 return vixl::aarch64::DRegister(location.reg());
Andreas Gampe878d58c2015-01-15 23:24:00 -080093}
94
Evgeny Astigeevich7d48dcd2019-10-16 12:46:28 +010095inline vixl::aarch64::VRegister QRegisterFrom(Location location) {
Artem Serovd4bccf12017-04-03 18:47:32 +010096 DCHECK(location.IsFpuRegister()) << location;
Artem Serova07de552020-11-01 22:42:43 +000097 return vixl::aarch64::QRegister(location.reg());
Artem Serovd4bccf12017-04-03 18:47:32 +010098}
99
Evgeny Astigeevich7d48dcd2019-10-16 12:46:28 +0100100inline vixl::aarch64::VRegister VRegisterFrom(Location location) {
Artem Serovb31f91f2017-04-05 11:31:19 +0100101 DCHECK(location.IsFpuRegister()) << location;
Artem Serova07de552020-11-01 22:42:43 +0000102 return vixl::aarch64::VRegister(location.reg());
Artem Serovb31f91f2017-04-05 11:31:19 +0100103}
104
Artem Serov8ba4de12019-12-04 21:10:23 +0000105inline vixl::aarch64::ZRegister ZRegisterFrom(Location location) {
106 DCHECK(location.IsFpuRegister()) << location;
107 return vixl::aarch64::ZRegister(location.reg());
108}
109
Evgeny Astigeevich7d48dcd2019-10-16 12:46:28 +0100110inline vixl::aarch64::VRegister SRegisterFrom(Location location) {
Roland Levillain3a448e42016-04-01 18:37:46 +0100111 DCHECK(location.IsFpuRegister()) << location;
Artem Serova07de552020-11-01 22:42:43 +0000112 return vixl::aarch64::SRegister(location.reg());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800113}
114
Roland Levillain4f2e0882019-12-01 09:57:10 +0000115inline vixl::aarch64::VRegister HRegisterFrom(Location location) {
Usama Arif457e9fa2019-11-11 15:29:59 +0000116 DCHECK(location.IsFpuRegister()) << location;
Artem Serova07de552020-11-01 22:42:43 +0000117 return vixl::aarch64::HRegister(location.reg());
Usama Arif457e9fa2019-11-11 15:29:59 +0000118}
119
Evgeny Astigeevich7d48dcd2019-10-16 12:46:28 +0100120inline vixl::aarch64::VRegister FPRegisterFrom(Location location, DataType::Type type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100121 DCHECK(DataType::IsFloatingPointType(type)) << type;
122 return type == DataType::Type::kFloat64 ? DRegisterFrom(location) : SRegisterFrom(location);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800123}
124
Evgeny Astigeevich7d48dcd2019-10-16 12:46:28 +0100125inline vixl::aarch64::VRegister OutputFPRegister(HInstruction* instr) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800126 return FPRegisterFrom(instr->GetLocations()->Out(), instr->GetType());
127}
128
Evgeny Astigeevich7d48dcd2019-10-16 12:46:28 +0100129inline vixl::aarch64::VRegister InputFPRegisterAt(HInstruction* instr, int input_index) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800130 return FPRegisterFrom(instr->GetLocations()->InAt(input_index),
131 instr->InputAt(input_index)->GetType());
132}
133
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100134inline vixl::aarch64::CPURegister CPURegisterFrom(Location location, DataType::Type type) {
135 return DataType::IsFloatingPointType(type)
Scott Wakeling97c72b72016-06-24 16:19:36 +0100136 ? vixl::aarch64::CPURegister(FPRegisterFrom(location, type))
137 : vixl::aarch64::CPURegister(RegisterFrom(location, type));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800138}
139
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100140inline vixl::aarch64::CPURegister OutputCPURegister(HInstruction* instr) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100141 return DataType::IsFloatingPointType(instr->GetType())
Scott Wakeling97c72b72016-06-24 16:19:36 +0100142 ? static_cast<vixl::aarch64::CPURegister>(OutputFPRegister(instr))
143 : static_cast<vixl::aarch64::CPURegister>(OutputRegister(instr));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800144}
145
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100146inline vixl::aarch64::CPURegister InputCPURegisterAt(HInstruction* instr, int index) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100147 return DataType::IsFloatingPointType(instr->InputAt(index)->GetType())
Scott Wakeling97c72b72016-06-24 16:19:36 +0100148 ? static_cast<vixl::aarch64::CPURegister>(InputFPRegisterAt(instr, index))
149 : static_cast<vixl::aarch64::CPURegister>(InputRegisterAt(instr, index));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800150}
151
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100152inline vixl::aarch64::CPURegister InputCPURegisterOrZeroRegAt(HInstruction* instr,
Alexandre Ramesbe919d92016-08-23 18:33:36 +0100153 int index) {
154 HInstruction* input = instr->InputAt(index);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100155 DataType::Type input_type = input->GetType();
Alexandre Ramesbe919d92016-08-23 18:33:36 +0100156 if (input->IsConstant() && input->AsConstant()->IsZeroBitPattern()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100157 return (DataType::Size(input_type) >= vixl::aarch64::kXRegSizeInBytes)
Scott Wakeling79db9972017-01-19 14:08:42 +0000158 ? vixl::aarch64::Register(vixl::aarch64::xzr)
159 : vixl::aarch64::Register(vixl::aarch64::wzr);
Alexandre Ramesbe919d92016-08-23 18:33:36 +0100160 }
161 return InputCPURegisterAt(instr, index);
162}
163
Evgeny Astigeevichf9e90542018-06-25 13:43:53 +0100164inline int64_t Int64FromLocation(Location location) {
165 return Int64FromConstant(location.GetConstant());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800166}
167
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100168inline vixl::aarch64::Operand OperandFrom(Location location, DataType::Type type) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800169 if (location.IsRegister()) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100170 return vixl::aarch64::Operand(RegisterFrom(location, type));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800171 } else {
Evgeny Astigeevichf9e90542018-06-25 13:43:53 +0100172 return vixl::aarch64::Operand(Int64FromLocation(location));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800173 }
174}
175
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100176inline vixl::aarch64::Operand InputOperandAt(HInstruction* instr, int input_index) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800177 return OperandFrom(instr->GetLocations()->InAt(input_index),
178 instr->InputAt(input_index)->GetType());
179}
180
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100181inline vixl::aarch64::MemOperand StackOperandFrom(Location location) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100182 return vixl::aarch64::MemOperand(vixl::aarch64::sp, location.GetStackIndex());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800183}
184
Artem Serov55ab7e82020-04-27 21:02:28 +0100185inline vixl::aarch64::SVEMemOperand SveStackOperandFrom(Location location) {
186 return vixl::aarch64::SVEMemOperand(vixl::aarch64::sp, location.GetStackIndex());
187}
188
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100189inline vixl::aarch64::MemOperand HeapOperand(const vixl::aarch64::Register& base,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100190 size_t offset = 0) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800191 // A heap reference must be 32bit, so fit in a W register.
192 DCHECK(base.IsW());
Scott Wakeling97c72b72016-06-24 16:19:36 +0100193 return vixl::aarch64::MemOperand(base.X(), offset);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800194}
195
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100196inline vixl::aarch64::MemOperand HeapOperand(const vixl::aarch64::Register& base,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100197 const vixl::aarch64::Register& regoffset,
198 vixl::aarch64::Shift shift = vixl::aarch64::LSL,
199 unsigned shift_amount = 0) {
Alexandre Rames82000b02015-07-07 11:34:16 +0100200 // A heap reference must be 32bit, so fit in a W register.
201 DCHECK(base.IsW());
Scott Wakeling97c72b72016-06-24 16:19:36 +0100202 return vixl::aarch64::MemOperand(base.X(), regoffset, shift, shift_amount);
Alexandre Rames82000b02015-07-07 11:34:16 +0100203}
204
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100205inline vixl::aarch64::MemOperand HeapOperand(const vixl::aarch64::Register& base,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100206 Offset offset) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800207 return HeapOperand(base, offset.SizeValue());
208}
209
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100210inline vixl::aarch64::MemOperand HeapOperandFrom(Location location, Offset offset) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100211 return HeapOperand(RegisterFrom(location, DataType::Type::kReference), offset);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800212}
213
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100214inline Location LocationFrom(const vixl::aarch64::Register& reg) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100215 return Location::RegisterLocation(ARTRegCodeFromVIXL(reg.GetCode()));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800216}
217
Evgeny Astigeevich7d48dcd2019-10-16 12:46:28 +0100218inline Location LocationFrom(const vixl::aarch64::VRegister& fpreg) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100219 return Location::FpuRegisterLocation(fpreg.GetCode());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800220}
221
Artem Serov55ab7e82020-04-27 21:02:28 +0100222inline Location LocationFrom(const vixl::aarch64::ZRegister& zreg) {
223 return Location::FpuRegisterLocation(zreg.GetCode());
224}
225
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100226inline vixl::aarch64::Operand OperandFromMemOperand(
Scott Wakeling97c72b72016-06-24 16:19:36 +0100227 const vixl::aarch64::MemOperand& mem_op) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800228 if (mem_op.IsImmediateOffset()) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100229 return vixl::aarch64::Operand(mem_op.GetOffset());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800230 } else {
231 DCHECK(mem_op.IsRegisterOffset());
Scott Wakeling97c72b72016-06-24 16:19:36 +0100232 if (mem_op.GetExtend() != vixl::aarch64::NO_EXTEND) {
233 return vixl::aarch64::Operand(mem_op.GetRegisterOffset(),
234 mem_op.GetExtend(),
235 mem_op.GetShiftAmount());
236 } else if (mem_op.GetShift() != vixl::aarch64::NO_SHIFT) {
237 return vixl::aarch64::Operand(mem_op.GetRegisterOffset(),
238 mem_op.GetShift(),
239 mem_op.GetShiftAmount());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800240 } else {
241 LOG(FATAL) << "Should not reach here";
242 UNREACHABLE();
243 }
244 }
245}
246
Petre-Ionut Tudor2227fe42018-04-20 17:12:05 +0100247inline bool AddSubCanEncodeAsImmediate(int64_t value) {
248 // If `value` does not fit but `-value` does, VIXL will automatically use
249 // the 'opposite' instruction.
250 return vixl::aarch64::Assembler::IsImmAddSub(value)
251 || vixl::aarch64::Assembler::IsImmAddSub(-value);
252}
253
Artem Serov8dfe7462017-06-01 14:28:48 +0100254inline bool Arm64CanEncodeConstantAsImmediate(HConstant* constant, HInstruction* instr) {
255 int64_t value = CodeGenerator::GetInt64ValueOf(constant);
256
257 // TODO: Improve this when IsSIMDConstantEncodable method is implemented in VIXL.
258 if (instr->IsVecReplicateScalar()) {
259 if (constant->IsLongConstant()) {
260 return false;
261 } else if (constant->IsFloatConstant()) {
262 return vixl::aarch64::Assembler::IsImmFP32(constant->AsFloatConstant()->GetValue());
263 } else if (constant->IsDoubleConstant()) {
264 return vixl::aarch64::Assembler::IsImmFP64(constant->AsDoubleConstant()->GetValue());
265 }
266 return IsUint<8>(value);
267 }
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000268
Petre-Ionut Tudor2227fe42018-04-20 17:12:05 +0100269 // Code generation for Min/Max:
270 // Cmp left_op, right_op
271 // Csel dst, left_op, right_op, cond
272 if (instr->IsMin() || instr->IsMax()) {
273 if (constant->GetUses().HasExactlyOneElement()) {
274 // If value can be encoded as immediate for the Cmp, then let VIXL handle
275 // the constant generation for the Csel.
276 return AddSubCanEncodeAsImmediate(value);
277 }
278 // These values are encodable as immediates for Cmp and VIXL will use csinc and csinv
279 // with the zr register as right_op, hence no constant generation is required.
280 return constant->IsZeroBitPattern() || constant->IsOne() || constant->IsMinusOne();
281 }
282
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000283 // For single uses we let VIXL handle the constant generation since it will
284 // use registers that are not managed by the register allocator (wip0, wip1).
Vladimir Marko46817b82016-03-29 12:21:58 +0100285 if (constant->GetUses().HasExactlyOneElement()) {
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000286 return true;
287 }
288
Scott Wakeling40a04bf2015-12-11 09:50:36 +0000289 // Our code generator ensures shift distances are within an encodable range.
290 if (instr->IsRor()) {
291 return true;
292 }
293
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100294 if (instr->IsAnd() || instr->IsOr() || instr->IsXor()) {
295 // Uses logical operations.
Scott Wakeling97c72b72016-06-24 16:19:36 +0100296 return vixl::aarch64::Assembler::IsImmLogical(value, vixl::aarch64::kXRegSize);
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100297 } else if (instr->IsNeg()) {
298 // Uses mov -immediate.
Scott Wakeling97c72b72016-06-24 16:19:36 +0100299 return vixl::aarch64::Assembler::IsImmMovn(value, vixl::aarch64::kXRegSize);
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100300 } else {
301 DCHECK(instr->IsAdd() ||
Artem Serov328429f2016-07-06 16:23:04 +0100302 instr->IsIntermediateAddress() ||
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100303 instr->IsBoundsCheck() ||
304 instr->IsCompare() ||
305 instr->IsCondition() ||
Roland Levillain22c49222016-03-18 14:04:28 +0000306 instr->IsSub())
307 << instr->DebugName();
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000308 // Uses aliases of ADD/SUB instructions.
Petre-Ionut Tudor2227fe42018-04-20 17:12:05 +0100309 return AddSubCanEncodeAsImmediate(value);
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000310 }
311}
312
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100313inline Location ARM64EncodableConstantOrRegister(HInstruction* constant,
Artem Serov8ba4de12019-12-04 21:10:23 +0000314 HInstruction* instr) {
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000315 if (constant->IsConstant()
Artem Serov8dfe7462017-06-01 14:28:48 +0100316 && Arm64CanEncodeConstantAsImmediate(constant->AsConstant(), instr)) {
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000317 return Location::ConstantLocation(constant->AsConstant());
318 }
319
320 return Location::RequiresRegister();
321}
322
Zheng Xuda403092015-04-24 17:35:39 +0800323// Check if registers in art register set have the same register code in vixl. If the register
324// codes are same, we can initialize vixl register list simply by the register masks. Currently,
325// only SP/WSP and ZXR/WZR codes are different between art and vixl.
326// Note: This function is only used for debug checks.
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100327inline bool ArtVixlRegCodeCoherentForRegSet(uint32_t art_core_registers,
Vladimir Marko804b03f2016-09-14 16:26:36 +0100328 size_t num_core,
329 uint32_t art_fpu_registers,
330 size_t num_fpu) {
Zheng Xuda403092015-04-24 17:35:39 +0800331 // The register masks won't work if the number of register is larger than 32.
332 DCHECK_GE(sizeof(art_core_registers) * 8, num_core);
333 DCHECK_GE(sizeof(art_fpu_registers) * 8, num_fpu);
334 for (size_t art_reg_code = 0; art_reg_code < num_core; ++art_reg_code) {
335 if (RegisterSet::Contains(art_core_registers, art_reg_code)) {
336 if (art_reg_code != static_cast<size_t>(VIXLRegCodeFromART(art_reg_code))) {
337 return false;
338 }
339 }
340 }
341 // There is no register code translation for float registers.
342 return true;
343}
344
Anton Kirilov74234da2017-01-13 14:42:47 +0000345inline vixl::aarch64::Shift ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) {
Alexandre Rames8626b742015-11-25 16:28:08 +0000346 switch (op_kind) {
Anton Kirilov74234da2017-01-13 14:42:47 +0000347 case HDataProcWithShifterOp::kASR: return vixl::aarch64::ASR;
348 case HDataProcWithShifterOp::kLSL: return vixl::aarch64::LSL;
349 case HDataProcWithShifterOp::kLSR: return vixl::aarch64::LSR;
Alexandre Rames8626b742015-11-25 16:28:08 +0000350 default:
351 LOG(FATAL) << "Unexpected op kind " << op_kind;
352 UNREACHABLE();
Scott Wakeling97c72b72016-06-24 16:19:36 +0100353 return vixl::aarch64::NO_SHIFT;
Alexandre Rames8626b742015-11-25 16:28:08 +0000354 }
355}
356
Anton Kirilov74234da2017-01-13 14:42:47 +0000357inline vixl::aarch64::Extend ExtendFromOpKind(HDataProcWithShifterOp::OpKind op_kind) {
Alexandre Rames8626b742015-11-25 16:28:08 +0000358 switch (op_kind) {
Anton Kirilov74234da2017-01-13 14:42:47 +0000359 case HDataProcWithShifterOp::kUXTB: return vixl::aarch64::UXTB;
360 case HDataProcWithShifterOp::kUXTH: return vixl::aarch64::UXTH;
361 case HDataProcWithShifterOp::kUXTW: return vixl::aarch64::UXTW;
362 case HDataProcWithShifterOp::kSXTB: return vixl::aarch64::SXTB;
363 case HDataProcWithShifterOp::kSXTH: return vixl::aarch64::SXTH;
364 case HDataProcWithShifterOp::kSXTW: return vixl::aarch64::SXTW;
Alexandre Rames8626b742015-11-25 16:28:08 +0000365 default:
366 LOG(FATAL) << "Unexpected op kind " << op_kind;
367 UNREACHABLE();
Scott Wakeling97c72b72016-06-24 16:19:36 +0100368 return vixl::aarch64::NO_EXTEND;
Alexandre Rames8626b742015-11-25 16:28:08 +0000369 }
370}
371
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100372inline bool ShifterOperandSupportsExtension(HInstruction* instruction) {
Vladimir Marko33bff252017-11-01 14:35:42 +0000373 DCHECK(HasShifterOperand(instruction, InstructionSet::kArm64));
Alexandre Rames8626b742015-11-25 16:28:08 +0000374 // Although the `neg` instruction is an alias of the `sub` instruction, `HNeg`
375 // does *not* support extension. This is because the `extended register` form
376 // of the `sub` instruction interprets the left register with code 31 as the
377 // stack pointer and not the zero register. (So does the `immediate` form.) In
378 // the other form `shifted register, the register with code 31 is interpreted
379 // as the zero register.
380 return instruction->IsAdd() || instruction->IsSub();
381}
382
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100383inline bool IsConstantZeroBitPattern(const HInstruction* instruction) {
Alexandre Ramesbe919d92016-08-23 18:33:36 +0100384 return instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern();
385}
386
Andreas Gampe878d58c2015-01-15 23:24:00 -0800387} // namespace helpers
388} // namespace arm64
389} // namespace art
390
391#endif // ART_COMPILER_OPTIMIZING_COMMON_ARM64_H_