18626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames/* 28626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames * Copyright (C) 2015 The Android Open Source Project 38626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames * 48626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames * Licensed under the Apache License, Version 2.0 (the "License"); 58626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames * you may not use this file except in compliance with the License. 68626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames * You may obtain a copy of the License at 78626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames * 88626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames * http://www.apache.org/licenses/LICENSE-2.0 98626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames * 108626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames * Unless required by applicable law or agreed to in writing, software 118626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames * distributed under the License is distributed on an "AS IS" BASIS, 128626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames * See the License for the specific language governing permissions and 148626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames * limitations under the License. 158626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames */ 168626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames 178626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames#include "common_arm64.h" 188626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames#include "nodes.h" 198626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames 208626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Ramesnamespace art { 218626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames 228626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Ramesusing arm64::helpers::CanFitInShifterOperand; 238626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames 248626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Ramesvoid HArm64DataProcWithShifterOp::GetOpInfoFromInstruction(HInstruction* instruction, 258626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames /*out*/OpKind* op_kind, 268626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames /*out*/int* shift_amount) { 278626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames DCHECK(CanFitInShifterOperand(instruction)); 288626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames if (instruction->IsShl()) { 298626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames *op_kind = kLSL; 308626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames *shift_amount = instruction->AsShl()->GetRight()->AsIntConstant()->GetValue(); 318626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames } else if (instruction->IsShr()) { 328626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames *op_kind = kASR; 338626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames *shift_amount = instruction->AsShr()->GetRight()->AsIntConstant()->GetValue(); 348626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames } else if (instruction->IsUShr()) { 358626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames *op_kind = kLSR; 368626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames *shift_amount = instruction->AsUShr()->GetRight()->AsIntConstant()->GetValue(); 378626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames } else { 388626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames DCHECK(instruction->IsTypeConversion()); 398626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames Primitive::Type result_type = instruction->AsTypeConversion()->GetResultType(); 408626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames Primitive::Type input_type = instruction->AsTypeConversion()->GetInputType(); 418626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames int result_size = Primitive::ComponentSize(result_type); 428626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames int input_size = Primitive::ComponentSize(input_type); 438626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames int min_size = std::min(result_size, input_size); 448626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames // This follows the logic in 458626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames // `InstructionCodeGeneratorARM64::VisitTypeConversion()`. 468626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames if (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimLong) { 478626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames // There is actually nothing to do. The register will be used as a W 488626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames // register, discarding the top bits. This is represented by the default 498626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames // encoding 'LSL 0'. 508626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames *op_kind = kLSL; 518626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames *shift_amount = 0; 528626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames } else if (result_type == Primitive::kPrimChar || 538626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames (input_type == Primitive::kPrimChar && input_size < result_size)) { 548626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames *op_kind = kUXTH; 558626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames } else { 568626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames switch (min_size) { 578626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames case 1: *op_kind = kSXTB; break; 588626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames case 2: *op_kind = kSXTH; break; 598626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames case 4: *op_kind = kSXTW; break; 608626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames default: 618626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames LOG(FATAL) << "Unexpected min size " << min_size; 628626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames } 638626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames } 648626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames } 658626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames} 668626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames 678626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Ramesstd::ostream& operator<<(std::ostream& os, const HArm64DataProcWithShifterOp::OpKind op) { 688626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames switch (op) { 698626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames case HArm64DataProcWithShifterOp::kLSL: return os << "LSL"; 708626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames case HArm64DataProcWithShifterOp::kLSR: return os << "LSR"; 718626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames case HArm64DataProcWithShifterOp::kASR: return os << "ASR"; 728626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames case HArm64DataProcWithShifterOp::kUXTB: return os << "UXTB"; 738626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames case HArm64DataProcWithShifterOp::kUXTH: return os << "UXTH"; 748626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames case HArm64DataProcWithShifterOp::kUXTW: return os << "UXTW"; 758626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames case HArm64DataProcWithShifterOp::kSXTB: return os << "SXTB"; 768626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames case HArm64DataProcWithShifterOp::kSXTH: return os << "SXTH"; 778626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames case HArm64DataProcWithShifterOp::kSXTW: return os << "SXTW"; 788626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames default: 798626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames LOG(FATAL) << "Invalid OpKind " << static_cast<int>(op); 808626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames UNREACHABLE(); 818626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames } 828626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames} 838626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames 848626b741716390a0119ffeb88b5b9fcf08e13010Alexandre Rames} // namespace art 85