blob: f982523634eda741438af7c97d854a6235ed78c9 [file] [log] [blame]
Alexandre Rames8626b742015-11-25 16:28:08 +00001/*
Anton Kirilov74234da2017-01-13 14:42:47 +00002 * Copyright (C) 2017 The Android Open Source Project
Alexandre Rames8626b742015-11-25 16:28:08 +00003 *
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
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070017// Note: this include order may seem strange and is against the regular style. However it is the
18// required order as nodes_shared does not have the right dependency chain and compilation
19// will fail (as AsType on HInstruction will be defined before the full Instruction).
20#include "nodes.h"
21
Anton Kirilov74234da2017-01-13 14:42:47 +000022#include "nodes_shared.h"
Alexandre Rames8626b742015-11-25 16:28:08 +000023
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070024#include "common_arm64.h"
25
Alexandre Rames8626b742015-11-25 16:28:08 +000026namespace art {
27
Anton Kirilov74234da2017-01-13 14:42:47 +000028using helpers::CanFitInShifterOperand;
Alexandre Rames8626b742015-11-25 16:28:08 +000029
Anton Kirilov74234da2017-01-13 14:42:47 +000030void HDataProcWithShifterOp::GetOpInfoFromInstruction(HInstruction* instruction,
31 /*out*/OpKind* op_kind,
32 /*out*/int* shift_amount) {
Alexandre Rames8626b742015-11-25 16:28:08 +000033 DCHECK(CanFitInShifterOperand(instruction));
34 if (instruction->IsShl()) {
35 *op_kind = kLSL;
36 *shift_amount = instruction->AsShl()->GetRight()->AsIntConstant()->GetValue();
37 } else if (instruction->IsShr()) {
38 *op_kind = kASR;
39 *shift_amount = instruction->AsShr()->GetRight()->AsIntConstant()->GetValue();
40 } else if (instruction->IsUShr()) {
41 *op_kind = kLSR;
42 *shift_amount = instruction->AsUShr()->GetRight()->AsIntConstant()->GetValue();
43 } else {
44 DCHECK(instruction->IsTypeConversion());
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010045 DataType::Type result_type = instruction->AsTypeConversion()->GetResultType();
46 DataType::Type input_type = instruction->AsTypeConversion()->GetInputType();
47 int result_size = DataType::Size(result_type);
48 int input_size = DataType::Size(input_type);
Alexandre Rames8626b742015-11-25 16:28:08 +000049 int min_size = std::min(result_size, input_size);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010050 if (result_type == DataType::Type::kInt32 && input_type == DataType::Type::kInt64) {
Anton Kirilov74234da2017-01-13 14:42:47 +000051 // There is actually nothing to do. On ARM the high register from the
52 // pair will be ignored. On ARM64 the register will be used as a W
53 // register, discarding the top bits. This is represented by the
54 // default encoding 'LSL 0'.
Alexandre Rames8626b742015-11-25 16:28:08 +000055 *op_kind = kLSL;
56 *shift_amount = 0;
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010057 } else if (result_type == DataType::Type::kUint16 ||
58 (input_type == DataType::Type::kUint16 && input_size < result_size)) {
Alexandre Rames8626b742015-11-25 16:28:08 +000059 *op_kind = kUXTH;
60 } else {
61 switch (min_size) {
62 case 1: *op_kind = kSXTB; break;
63 case 2: *op_kind = kSXTH; break;
64 case 4: *op_kind = kSXTW; break;
65 default:
66 LOG(FATAL) << "Unexpected min size " << min_size;
67 }
68 }
69 }
70}
71
Anton Kirilov74234da2017-01-13 14:42:47 +000072std::ostream& operator<<(std::ostream& os, const HDataProcWithShifterOp::OpKind op) {
Alexandre Rames8626b742015-11-25 16:28:08 +000073 switch (op) {
Anton Kirilov74234da2017-01-13 14:42:47 +000074 case HDataProcWithShifterOp::kLSL: return os << "LSL";
75 case HDataProcWithShifterOp::kLSR: return os << "LSR";
76 case HDataProcWithShifterOp::kASR: return os << "ASR";
77 case HDataProcWithShifterOp::kUXTB: return os << "UXTB";
78 case HDataProcWithShifterOp::kUXTH: return os << "UXTH";
79 case HDataProcWithShifterOp::kUXTW: return os << "UXTW";
80 case HDataProcWithShifterOp::kSXTB: return os << "SXTB";
81 case HDataProcWithShifterOp::kSXTH: return os << "SXTH";
82 case HDataProcWithShifterOp::kSXTW: return os << "SXTW";
Alexandre Rames8626b742015-11-25 16:28:08 +000083 default:
84 LOG(FATAL) << "Invalid OpKind " << static_cast<int>(op);
85 UNREACHABLE();
86 }
87}
88
89} // namespace art