1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "aarch64_isa.h" 17 #include "insn.h" 18 19 namespace maplebe { 20 /* 21 * Get the ldp/stp corresponding to ldr/str 22 * mop : a ldr or str machine operator 23 */ GetMopPair(MOperator mop)24MOperator GetMopPair(MOperator mop) 25 { 26 switch (mop) { 27 case MOP_xldr: 28 return MOP_xldp; 29 case MOP_wldr: 30 return MOP_wldp; 31 case MOP_xstr: 32 return MOP_xstp; 33 case MOP_wstr: 34 return MOP_wstp; 35 case MOP_dldr: 36 return MOP_dldp; 37 case MOP_qldr: 38 return MOP_qldp; 39 case MOP_sldr: 40 return MOP_sldp; 41 case MOP_dstr: 42 return MOP_dstp; 43 case MOP_sstr: 44 return MOP_sstp; 45 case MOP_qstr: 46 return MOP_qstp; 47 default: 48 DEBUG_ASSERT(false, "should not run here"); 49 return MOP_undef; 50 } 51 } 52 namespace AArch64isa { FlipConditionOp(MOperator flippedOp)53MOperator FlipConditionOp(MOperator flippedOp) 54 { 55 switch (flippedOp) { 56 case AArch64MopT::MOP_beq: 57 return AArch64MopT::MOP_bne; 58 case AArch64MopT::MOP_bge: 59 return AArch64MopT::MOP_blt; 60 case AArch64MopT::MOP_bgt: 61 return AArch64MopT::MOP_ble; 62 case AArch64MopT::MOP_bhi: 63 return AArch64MopT::MOP_bls; 64 case AArch64MopT::MOP_bhs: 65 return AArch64MopT::MOP_blo; 66 case AArch64MopT::MOP_ble: 67 return AArch64MopT::MOP_bgt; 68 case AArch64MopT::MOP_blo: 69 return AArch64MopT::MOP_bhs; 70 case AArch64MopT::MOP_bls: 71 return AArch64MopT::MOP_bhi; 72 case AArch64MopT::MOP_blt: 73 return AArch64MopT::MOP_bge; 74 case AArch64MopT::MOP_bne: 75 return AArch64MopT::MOP_beq; 76 case AArch64MopT::MOP_bpl: 77 return AArch64MopT::MOP_bmi; 78 case AArch64MopT::MOP_xcbnz: 79 return AArch64MopT::MOP_xcbz; 80 case AArch64MopT::MOP_wcbnz: 81 return AArch64MopT::MOP_wcbz; 82 case AArch64MopT::MOP_xcbz: 83 return AArch64MopT::MOP_xcbnz; 84 case AArch64MopT::MOP_wcbz: 85 return AArch64MopT::MOP_wcbnz; 86 case AArch64MopT::MOP_wtbnz: 87 return AArch64MopT::MOP_wtbz; 88 case AArch64MopT::MOP_wtbz: 89 return AArch64MopT::MOP_wtbnz; 90 case AArch64MopT::MOP_xtbnz: 91 return AArch64MopT::MOP_xtbz; 92 case AArch64MopT::MOP_xtbz: 93 return AArch64MopT::MOP_xtbnz; 94 default: 95 break; 96 } 97 return AArch64MopT::MOP_undef; 98 } 99 GetJumpTargetIdx(const Insn & insn)100uint32 GetJumpTargetIdx(const Insn &insn) 101 { 102 MOperator curMop = insn.GetMachineOpcode(); 103 switch (curMop) { 104 /* unconditional jump */ 105 case MOP_xuncond: { 106 return kInsnFirstOpnd; 107 } 108 case MOP_xbr: { 109 DEBUG_ASSERT(insn.GetOperandSize() == 2, "ERR"); // must have 2 110 return kInsnSecondOpnd; 111 } 112 /* conditional jump */ 113 case MOP_bmi: 114 case MOP_bvc: 115 case MOP_bls: 116 case MOP_blt: 117 case MOP_ble: 118 case MOP_blo: 119 case MOP_beq: 120 case MOP_bpl: 121 case MOP_bhs: 122 case MOP_bvs: 123 case MOP_bhi: 124 case MOP_bgt: 125 case MOP_bge: 126 case MOP_bne: 127 case MOP_wcbz: 128 case MOP_xcbz: 129 case MOP_wcbnz: 130 case MOP_xcbnz: { 131 return kInsnSecondOpnd; 132 } 133 case MOP_wtbz: 134 case MOP_xtbz: 135 case MOP_wtbnz: 136 case MOP_xtbnz: { 137 return kInsnThirdOpnd; 138 } 139 default: 140 CHECK_FATAL(false, "Not a jump insn"); 141 } 142 return kInsnFirstOpnd; 143 } 144 } /* namespace AArch64isa */ 145 } /* namespace maplebe */ 146