Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1 | /* |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2 | * Copyright (C) 2017 The Android Open Source Project |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 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 | |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 17 | // 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 Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 22 | #include "nodes_shared.h" |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 23 | |
Artem Serov | a07de55 | 2020-11-01 22:42:43 +0000 | [diff] [blame] | 24 | #include "instruction_simplifier_shared.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 25 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 26 | namespace art { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 27 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 28 | using helpers::CanFitInShifterOperand; |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 29 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 30 | void HDataProcWithShifterOp::GetOpInfoFromInstruction(HInstruction* instruction, |
| 31 | /*out*/OpKind* op_kind, |
| 32 | /*out*/int* shift_amount) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 33 | 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 Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 45 | 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 Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 49 | int min_size = std::min(result_size, input_size); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 50 | if (result_type == DataType::Type::kInt32 && input_type == DataType::Type::kInt64) { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 51 | // 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 Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 55 | *op_kind = kLSL; |
| 56 | *shift_amount = 0; |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 57 | } else if (result_type == DataType::Type::kUint8 || |
| 58 | (input_type == DataType::Type::kUint8 && input_size < result_size)) { |
| 59 | *op_kind = kUXTB; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 60 | } else if (result_type == DataType::Type::kUint16 || |
| 61 | (input_type == DataType::Type::kUint16 && input_size < result_size)) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 62 | *op_kind = kUXTH; |
| 63 | } else { |
| 64 | switch (min_size) { |
| 65 | case 1: *op_kind = kSXTB; break; |
| 66 | case 2: *op_kind = kSXTH; break; |
| 67 | case 4: *op_kind = kSXTW; break; |
| 68 | default: |
| 69 | LOG(FATAL) << "Unexpected min size " << min_size; |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 75 | std::ostream& operator<<(std::ostream& os, const HDataProcWithShifterOp::OpKind op) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 76 | switch (op) { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 77 | case HDataProcWithShifterOp::kLSL: return os << "LSL"; |
| 78 | case HDataProcWithShifterOp::kLSR: return os << "LSR"; |
| 79 | case HDataProcWithShifterOp::kASR: return os << "ASR"; |
| 80 | case HDataProcWithShifterOp::kUXTB: return os << "UXTB"; |
| 81 | case HDataProcWithShifterOp::kUXTH: return os << "UXTH"; |
| 82 | case HDataProcWithShifterOp::kUXTW: return os << "UXTW"; |
| 83 | case HDataProcWithShifterOp::kSXTB: return os << "SXTB"; |
| 84 | case HDataProcWithShifterOp::kSXTH: return os << "SXTH"; |
| 85 | case HDataProcWithShifterOp::kSXTW: return os << "SXTW"; |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 86 | default: |
| 87 | LOG(FATAL) << "Invalid OpKind " << static_cast<int>(op); |
| 88 | UNREACHABLE(); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | } // namespace art |