blob: e2ef8d52f22fbfea7b0f819f1ab975d2ee8a2892 [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
Vladimír Marko434d9682022-11-04 14:04:17 +000020#include "base/macros.h"
Alexandre Rames8626b742015-11-25 16:28:08 +000021#include "code_generator.h"
Anton Kirilov74234da2017-01-13 14:42:47 +000022#include "instruction_simplifier_shared.h"
Andreas Gampe878d58c2015-01-15 23:24:00 -080023#include "locations.h"
24#include "nodes.h"
25#include "utils/arm64/assembler_arm64.h"
Scott Wakeling97c72b72016-06-24 16:19:36 +010026
Artem Serovaf4e42a2016-08-08 15:11:24 +010027// TODO(VIXL): Make VIXL compile with -Wshadow.
28#pragma GCC diagnostic push
29#pragma GCC diagnostic ignored "-Wshadow"
30#include "aarch64/disasm-aarch64.h"
31#include "aarch64/macro-assembler-aarch64.h"
32#include "aarch64/simulator-aarch64.h"
33#pragma GCC diagnostic pop
Andreas Gampe878d58c2015-01-15 23:24:00 -080034
Vladimír Marko434d9682022-11-04 14:04:17 +000035namespace art HIDDEN {
Anton Kirilov74234da2017-01-13 14:42:47 +000036
37using helpers::CanFitInShifterOperand;
38using helpers::HasShifterOperand;
39
Andreas Gampe878d58c2015-01-15 23:24:00 -080040namespace arm64 {
41namespace helpers {
42
Andreas Gampe878d58c2015-01-15 23:24:00 -080043// Convenience helpers to ease conversion to and from VIXL operands.
44static_assert((SP == 31) && (WSP == 31) && (XZR == 32) && (WZR == 32),
45 "Unexpected values for register codes.");
46
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010047inline int VIXLRegCodeFromART(int code) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080048 if (code == SP) {
Scott Wakeling97c72b72016-06-24 16:19:36 +010049 return vixl::aarch64::kSPRegInternalCode;
Andreas Gampe878d58c2015-01-15 23:24:00 -080050 }
51 if (code == XZR) {
Scott Wakeling97c72b72016-06-24 16:19:36 +010052 return vixl::aarch64::kZeroRegCode;
Andreas Gampe878d58c2015-01-15 23:24:00 -080053 }
54 return code;
55}
56
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010057inline int ARTRegCodeFromVIXL(int code) {
Scott Wakeling97c72b72016-06-24 16:19:36 +010058 if (code == vixl::aarch64::kSPRegInternalCode) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080059 return SP;
60 }
Scott Wakeling97c72b72016-06-24 16:19:36 +010061 if (code == vixl::aarch64::kZeroRegCode) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080062 return XZR;
63 }
64 return code;
65}
66
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010067inline vixl::aarch64::Register XRegisterFrom(Location location) {
Roland Levillain3a448e42016-04-01 18:37:46 +010068 DCHECK(location.IsRegister()) << location;
Artem Serova07de552020-11-01 22:42:43 +000069 return vixl::aarch64::XRegister(VIXLRegCodeFromART(location.reg()));
Andreas Gampe878d58c2015-01-15 23:24:00 -080070}
71
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010072inline vixl::aarch64::Register WRegisterFrom(Location location) {
Roland Levillain3a448e42016-04-01 18:37:46 +010073 DCHECK(location.IsRegister()) << location;
Artem Serova07de552020-11-01 22:42:43 +000074 return vixl::aarch64::WRegister(VIXLRegCodeFromART(location.reg()));
Andreas Gampe878d58c2015-01-15 23:24:00 -080075}
76
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010077inline vixl::aarch64::Register RegisterFrom(Location location, DataType::Type type) {
78 DCHECK(type != DataType::Type::kVoid && !DataType::IsFloatingPointType(type)) << type;
79 return type == DataType::Type::kInt64 ? XRegisterFrom(location) : WRegisterFrom(location);
Andreas Gampe878d58c2015-01-15 23:24:00 -080080}
81
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010082inline vixl::aarch64::Register OutputRegister(HInstruction* instr) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080083 return RegisterFrom(instr->GetLocations()->Out(), instr->GetType());
84}
85
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010086inline vixl::aarch64::Register InputRegisterAt(HInstruction* instr, int input_index) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080087 return RegisterFrom(instr->GetLocations()->InAt(input_index),
88 instr->InputAt(input_index)->GetType());
89}
90
Evgeny Astigeevich7d48dcd2019-10-16 12:46:28 +010091inline vixl::aarch64::VRegister DRegisterFrom(Location location) {
Roland Levillain3a448e42016-04-01 18:37:46 +010092 DCHECK(location.IsFpuRegister()) << location;
Artem Serova07de552020-11-01 22:42:43 +000093 return vixl::aarch64::DRegister(location.reg());
Andreas Gampe878d58c2015-01-15 23:24:00 -080094}
95
Evgeny Astigeevich7d48dcd2019-10-16 12:46:28 +010096inline vixl::aarch64::VRegister QRegisterFrom(Location location) {
Artem Serovd4bccf12017-04-03 18:47:32 +010097 DCHECK(location.IsFpuRegister()) << location;
Artem Serova07de552020-11-01 22:42:43 +000098 return vixl::aarch64::QRegister(location.reg());
Artem Serovd4bccf12017-04-03 18:47:32 +010099}
100
Evgeny Astigeevich7d48dcd2019-10-16 12:46:28 +0100101inline vixl::aarch64::VRegister VRegisterFrom(Location location) {
Artem Serovb31f91f2017-04-05 11:31:19 +0100102 DCHECK(location.IsFpuRegister()) << location;
Artem Serova07de552020-11-01 22:42:43 +0000103 return vixl::aarch64::VRegister(location.reg());
Artem Serovb31f91f2017-04-05 11:31:19 +0100104}
105
Artem Serov8ba4de12019-12-04 21:10:23 +0000106inline vixl::aarch64::ZRegister ZRegisterFrom(Location location) {
107 DCHECK(location.IsFpuRegister()) << location;
108 return vixl::aarch64::ZRegister(location.reg());
109}
110
Evgeny Astigeevich7d48dcd2019-10-16 12:46:28 +0100111inline vixl::aarch64::VRegister SRegisterFrom(Location location) {
Roland Levillain3a448e42016-04-01 18:37:46 +0100112 DCHECK(location.IsFpuRegister()) << location;
Artem Serova07de552020-11-01 22:42:43 +0000113 return vixl::aarch64::SRegister(location.reg());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800114}
115
Roland Levillain4f2e0882019-12-01 09:57:10 +0000116inline vixl::aarch64::VRegister HRegisterFrom(Location location) {
Usama Arif457e9fa2019-11-11 15:29:59 +0000117 DCHECK(location.IsFpuRegister()) << location;
Artem Serova07de552020-11-01 22:42:43 +0000118 return vixl::aarch64::HRegister(location.reg());
Usama Arif457e9fa2019-11-11 15:29:59 +0000119}
120
Evgeny Astigeevich7d48dcd2019-10-16 12:46:28 +0100121inline vixl::aarch64::VRegister FPRegisterFrom(Location location, DataType::Type type) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100122 DCHECK(DataType::IsFloatingPointType(type)) << type;
123 return type == DataType::Type::kFloat64 ? DRegisterFrom(location) : SRegisterFrom(location);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800124}
125
Evgeny Astigeevich7d48dcd2019-10-16 12:46:28 +0100126inline vixl::aarch64::VRegister OutputFPRegister(HInstruction* instr) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800127 return FPRegisterFrom(instr->GetLocations()->Out(), instr->GetType());
128}
129
Evgeny Astigeevich7d48dcd2019-10-16 12:46:28 +0100130inline vixl::aarch64::VRegister InputFPRegisterAt(HInstruction* instr, int input_index) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800131 return FPRegisterFrom(instr->GetLocations()->InAt(input_index),
132 instr->InputAt(input_index)->GetType());
133}
134
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100135inline vixl::aarch64::CPURegister CPURegisterFrom(Location location, DataType::Type type) {
136 return DataType::IsFloatingPointType(type)
Scott Wakeling97c72b72016-06-24 16:19:36 +0100137 ? vixl::aarch64::CPURegister(FPRegisterFrom(location, type))
138 : vixl::aarch64::CPURegister(RegisterFrom(location, type));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800139}
140
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100141inline vixl::aarch64::CPURegister OutputCPURegister(HInstruction* instr) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100142 return DataType::IsFloatingPointType(instr->GetType())
Scott Wakeling97c72b72016-06-24 16:19:36 +0100143 ? static_cast<vixl::aarch64::CPURegister>(OutputFPRegister(instr))
144 : static_cast<vixl::aarch64::CPURegister>(OutputRegister(instr));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800145}
146
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100147inline vixl::aarch64::CPURegister InputCPURegisterAt(HInstruction* instr, int index) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100148 return DataType::IsFloatingPointType(instr->InputAt(index)->GetType())
Scott Wakeling97c72b72016-06-24 16:19:36 +0100149 ? static_cast<vixl::aarch64::CPURegister>(InputFPRegisterAt(instr, index))
150 : static_cast<vixl::aarch64::CPURegister>(InputRegisterAt(instr, index));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800151}
152
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100153inline vixl::aarch64::CPURegister InputCPURegisterOrZeroRegAt(HInstruction* instr,
Alexandre Ramesbe919d92016-08-23 18:33:36 +0100154 int index) {
155 HInstruction* input = instr->InputAt(index);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100156 DataType::Type input_type = input->GetType();
Vladimir Markod2be01c2023-04-05 12:21:09 +0000157 if (IsZeroBitPattern(input)) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100158 return (DataType::Size(input_type) >= vixl::aarch64::kXRegSizeInBytes)
Scott Wakeling79db9972017-01-19 14:08:42 +0000159 ? vixl::aarch64::Register(vixl::aarch64::xzr)
160 : vixl::aarch64::Register(vixl::aarch64::wzr);
Alexandre Ramesbe919d92016-08-23 18:33:36 +0100161 }
162 return InputCPURegisterAt(instr, index);
163}
164
Evgeny Astigeevichf9e90542018-06-25 13:43:53 +0100165inline int64_t Int64FromLocation(Location location) {
166 return Int64FromConstant(location.GetConstant());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800167}
168
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100169inline vixl::aarch64::Operand OperandFrom(Location location, DataType::Type type) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800170 if (location.IsRegister()) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100171 return vixl::aarch64::Operand(RegisterFrom(location, type));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800172 } else {
Evgeny Astigeevichf9e90542018-06-25 13:43:53 +0100173 return vixl::aarch64::Operand(Int64FromLocation(location));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800174 }
175}
176
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100177inline vixl::aarch64::Operand InputOperandAt(HInstruction* instr, int input_index) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800178 return OperandFrom(instr->GetLocations()->InAt(input_index),
179 instr->InputAt(input_index)->GetType());
180}
181
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100182inline vixl::aarch64::MemOperand StackOperandFrom(Location location) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100183 return vixl::aarch64::MemOperand(vixl::aarch64::sp, location.GetStackIndex());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800184}
185
Artem Serov55ab7e82020-04-27 21:02:28 +0100186inline vixl::aarch64::SVEMemOperand SveStackOperandFrom(Location location) {
187 return vixl::aarch64::SVEMemOperand(vixl::aarch64::sp, location.GetStackIndex());
188}
189
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100190inline vixl::aarch64::MemOperand HeapOperand(const vixl::aarch64::Register& base,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100191 size_t offset = 0) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800192 // A heap reference must be 32bit, so fit in a W register.
193 DCHECK(base.IsW());
Scott Wakeling97c72b72016-06-24 16:19:36 +0100194 return vixl::aarch64::MemOperand(base.X(), offset);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800195}
196
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100197inline vixl::aarch64::MemOperand HeapOperand(const vixl::aarch64::Register& base,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100198 const vixl::aarch64::Register& regoffset,
199 vixl::aarch64::Shift shift = vixl::aarch64::LSL,
200 unsigned shift_amount = 0) {
Alexandre Rames82000b02015-07-07 11:34:16 +0100201 // A heap reference must be 32bit, so fit in a W register.
202 DCHECK(base.IsW());
Scott Wakeling97c72b72016-06-24 16:19:36 +0100203 return vixl::aarch64::MemOperand(base.X(), regoffset, shift, shift_amount);
Alexandre Rames82000b02015-07-07 11:34:16 +0100204}
205
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100206inline vixl::aarch64::MemOperand HeapOperand(const vixl::aarch64::Register& base,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100207 Offset offset) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800208 return HeapOperand(base, offset.SizeValue());
209}
210
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100211inline vixl::aarch64::MemOperand HeapOperandFrom(Location location, Offset offset) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100212 return HeapOperand(RegisterFrom(location, DataType::Type::kReference), offset);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800213}
214
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100215inline Location LocationFrom(const vixl::aarch64::Register& reg) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100216 return Location::RegisterLocation(ARTRegCodeFromVIXL(reg.GetCode()));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800217}
218
Evgeny Astigeevich7d48dcd2019-10-16 12:46:28 +0100219inline Location LocationFrom(const vixl::aarch64::VRegister& fpreg) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100220 return Location::FpuRegisterLocation(fpreg.GetCode());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800221}
222
Artem Serov55ab7e82020-04-27 21:02:28 +0100223inline Location LocationFrom(const vixl::aarch64::ZRegister& zreg) {
224 return Location::FpuRegisterLocation(zreg.GetCode());
225}
226
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100227inline vixl::aarch64::Operand OperandFromMemOperand(
Scott Wakeling97c72b72016-06-24 16:19:36 +0100228 const vixl::aarch64::MemOperand& mem_op) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800229 if (mem_op.IsImmediateOffset()) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100230 return vixl::aarch64::Operand(mem_op.GetOffset());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800231 } else {
232 DCHECK(mem_op.IsRegisterOffset());
Scott Wakeling97c72b72016-06-24 16:19:36 +0100233 if (mem_op.GetExtend() != vixl::aarch64::NO_EXTEND) {
234 return vixl::aarch64::Operand(mem_op.GetRegisterOffset(),
235 mem_op.GetExtend(),
236 mem_op.GetShiftAmount());
237 } else if (mem_op.GetShift() != vixl::aarch64::NO_SHIFT) {
238 return vixl::aarch64::Operand(mem_op.GetRegisterOffset(),
239 mem_op.GetShift(),
240 mem_op.GetShiftAmount());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800241 } else {
242 LOG(FATAL) << "Should not reach here";
243 UNREACHABLE();
244 }
245 }
246}
247
Petre-Ionut Tudor2227fe42018-04-20 17:12:05 +0100248inline bool AddSubCanEncodeAsImmediate(int64_t value) {
249 // If `value` does not fit but `-value` does, VIXL will automatically use
250 // the 'opposite' instruction.
251 return vixl::aarch64::Assembler::IsImmAddSub(value)
252 || vixl::aarch64::Assembler::IsImmAddSub(-value);
253}
254
Artem Serov8dfe7462017-06-01 14:28:48 +0100255inline bool Arm64CanEncodeConstantAsImmediate(HConstant* constant, HInstruction* instr) {
256 int64_t value = CodeGenerator::GetInt64ValueOf(constant);
257
258 // TODO: Improve this when IsSIMDConstantEncodable method is implemented in VIXL.
259 if (instr->IsVecReplicateScalar()) {
260 if (constant->IsLongConstant()) {
261 return false;
262 } else if (constant->IsFloatConstant()) {
Vladimir Markocde64972023-04-25 16:40:06 +0000263 return vixl::aarch64::Assembler::IsImmFP32(constant->AsFloatConstant()->GetValue());
Artem Serov8dfe7462017-06-01 14:28:48 +0100264 } else if (constant->IsDoubleConstant()) {
Vladimir Markocde64972023-04-25 16:40:06 +0000265 return vixl::aarch64::Assembler::IsImmFP64(constant->AsDoubleConstant()->GetValue());
Artem Serov8dfe7462017-06-01 14:28:48 +0100266 }
267 return IsUint<8>(value);
268 }
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000269
Petre-Ionut Tudor2227fe42018-04-20 17:12:05 +0100270 // Code generation for Min/Max:
271 // Cmp left_op, right_op
272 // Csel dst, left_op, right_op, cond
273 if (instr->IsMin() || instr->IsMax()) {
274 if (constant->GetUses().HasExactlyOneElement()) {
275 // If value can be encoded as immediate for the Cmp, then let VIXL handle
276 // the constant generation for the Csel.
277 return AddSubCanEncodeAsImmediate(value);
278 }
279 // These values are encodable as immediates for Cmp and VIXL will use csinc and csinv
280 // with the zr register as right_op, hence no constant generation is required.
281 return constant->IsZeroBitPattern() || constant->IsOne() || constant->IsMinusOne();
282 }
283
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000284 // For single uses we let VIXL handle the constant generation since it will
285 // use registers that are not managed by the register allocator (wip0, wip1).
Vladimir Marko46817b82016-03-29 12:21:58 +0100286 if (constant->GetUses().HasExactlyOneElement()) {
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000287 return true;
288 }
289
Scott Wakeling40a04bf2015-12-11 09:50:36 +0000290 // Our code generator ensures shift distances are within an encodable range.
291 if (instr->IsRor()) {
292 return true;
293 }
294
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100295 if (instr->IsAnd() || instr->IsOr() || instr->IsXor()) {
296 // Uses logical operations.
Scott Wakeling97c72b72016-06-24 16:19:36 +0100297 return vixl::aarch64::Assembler::IsImmLogical(value, vixl::aarch64::kXRegSize);
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100298 } else if (instr->IsNeg()) {
299 // Uses mov -immediate.
Scott Wakeling97c72b72016-06-24 16:19:36 +0100300 return vixl::aarch64::Assembler::IsImmMovn(value, vixl::aarch64::kXRegSize);
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100301 } else {
302 DCHECK(instr->IsAdd() ||
Artem Serov328429f2016-07-06 16:23:04 +0100303 instr->IsIntermediateAddress() ||
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100304 instr->IsBoundsCheck() ||
305 instr->IsCompare() ||
306 instr->IsCondition() ||
Roland Levillain22c49222016-03-18 14:04:28 +0000307 instr->IsSub())
308 << instr->DebugName();
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000309 // Uses aliases of ADD/SUB instructions.
Petre-Ionut Tudor2227fe42018-04-20 17:12:05 +0100310 return AddSubCanEncodeAsImmediate(value);
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000311 }
312}
313
Vladimir Markof2eef5f2023-04-06 10:29:19 +0000314inline Location ARM64EncodableConstantOrRegister(HInstruction* constant, HInstruction* instr) {
Vladimir Markocde64972023-04-25 16:40:06 +0000315 if (constant->IsConstant() && Arm64CanEncodeConstantAsImmediate(constant->AsConstant(), instr)) {
Vladimir Markof76ca8c2023-04-05 15:24:41 +0000316 return Location::ConstantLocation(constant);
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000317 }
318
319 return Location::RequiresRegister();
320}
321
Zheng Xuda403092015-04-24 17:35:39 +0800322// Check if registers in art register set have the same register code in vixl. If the register
323// codes are same, we can initialize vixl register list simply by the register masks. Currently,
324// only SP/WSP and ZXR/WZR codes are different between art and vixl.
325// Note: This function is only used for debug checks.
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100326inline bool ArtVixlRegCodeCoherentForRegSet(uint32_t art_core_registers,
Vladimir Marko804b03f2016-09-14 16:26:36 +0100327 size_t num_core,
328 uint32_t art_fpu_registers,
329 size_t num_fpu) {
Zheng Xuda403092015-04-24 17:35:39 +0800330 // The register masks won't work if the number of register is larger than 32.
331 DCHECK_GE(sizeof(art_core_registers) * 8, num_core);
332 DCHECK_GE(sizeof(art_fpu_registers) * 8, num_fpu);
333 for (size_t art_reg_code = 0; art_reg_code < num_core; ++art_reg_code) {
334 if (RegisterSet::Contains(art_core_registers, art_reg_code)) {
335 if (art_reg_code != static_cast<size_t>(VIXLRegCodeFromART(art_reg_code))) {
336 return false;
337 }
338 }
339 }
340 // There is no register code translation for float registers.
341 return true;
342}
343
Anton Kirilov74234da2017-01-13 14:42:47 +0000344inline vixl::aarch64::Shift ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) {
Alexandre Rames8626b742015-11-25 16:28:08 +0000345 switch (op_kind) {
Anton Kirilov74234da2017-01-13 14:42:47 +0000346 case HDataProcWithShifterOp::kASR: return vixl::aarch64::ASR;
347 case HDataProcWithShifterOp::kLSL: return vixl::aarch64::LSL;
348 case HDataProcWithShifterOp::kLSR: return vixl::aarch64::LSR;
Alexandre Rames8626b742015-11-25 16:28:08 +0000349 default:
350 LOG(FATAL) << "Unexpected op kind " << op_kind;
351 UNREACHABLE();
Scott Wakeling97c72b72016-06-24 16:19:36 +0100352 return vixl::aarch64::NO_SHIFT;
Alexandre Rames8626b742015-11-25 16:28:08 +0000353 }
354}
355
Anton Kirilov74234da2017-01-13 14:42:47 +0000356inline vixl::aarch64::Extend ExtendFromOpKind(HDataProcWithShifterOp::OpKind op_kind) {
Alexandre Rames8626b742015-11-25 16:28:08 +0000357 switch (op_kind) {
Anton Kirilov74234da2017-01-13 14:42:47 +0000358 case HDataProcWithShifterOp::kUXTB: return vixl::aarch64::UXTB;
359 case HDataProcWithShifterOp::kUXTH: return vixl::aarch64::UXTH;
360 case HDataProcWithShifterOp::kUXTW: return vixl::aarch64::UXTW;
361 case HDataProcWithShifterOp::kSXTB: return vixl::aarch64::SXTB;
362 case HDataProcWithShifterOp::kSXTH: return vixl::aarch64::SXTH;
363 case HDataProcWithShifterOp::kSXTW: return vixl::aarch64::SXTW;
Alexandre Rames8626b742015-11-25 16:28:08 +0000364 default:
365 LOG(FATAL) << "Unexpected op kind " << op_kind;
366 UNREACHABLE();
Scott Wakeling97c72b72016-06-24 16:19:36 +0100367 return vixl::aarch64::NO_EXTEND;
Alexandre Rames8626b742015-11-25 16:28:08 +0000368 }
369}
370
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100371inline bool ShifterOperandSupportsExtension(HInstruction* instruction) {
Vladimir Marko33bff252017-11-01 14:35:42 +0000372 DCHECK(HasShifterOperand(instruction, InstructionSet::kArm64));
Alexandre Rames8626b742015-11-25 16:28:08 +0000373 // Although the `neg` instruction is an alias of the `sub` instruction, `HNeg`
374 // does *not* support extension. This is because the `extended register` form
375 // of the `sub` instruction interprets the left register with code 31 as the
376 // stack pointer and not the zero register. (So does the `immediate` form.) In
377 // the other form `shifted register, the register with code 31 is interpreted
378 // as the zero register.
379 return instruction->IsAdd() || instruction->IsSub();
380}
381
Andreas Gampe878d58c2015-01-15 23:24:00 -0800382} // namespace helpers
383} // namespace arm64
384} // namespace art
385
386#endif // ART_COMPILER_OPTIMIZING_COMMON_ARM64_H_