pred.isa revision 6276
1// -*- mode:c++ -*- 2 3// Copyright (c) 2007-2008 The Florida State University 4// All rights reserved. 5// 6// Redistribution and use in source and binary forms, with or without 7// modification, are permitted provided that the following conditions are 8// met: redistributions of source code must retain the above copyright 9// notice, this list of conditions and the following disclaimer; 10// redistributions in binary form must reproduce the above copyright 11// notice, this list of conditions and the following disclaimer in the 12// documentation and/or other materials provided with the distribution; 13// neither the name of the copyright holders nor the names of its 14// contributors may be used to endorse or promote products derived from 15// this software without specific prior written permission. 16// 17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28// 29// Authors: Stephen Hines 30 31//////////////////////////////////////////////////////////////////// 32// 33// Predicated Instruction Execution 34// 35 36let {{ 37 predicateTest = 'testPredicate(Cpsr, condCode)' 38}}; 39 40def template PredOpExecute {{ 41 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, Trace::InstRecord *traceData) const 42 { 43 Fault fault = NoFault; 44 uint64_t resTemp = 0; 45 resTemp = resTemp; 46 %(op_decl)s; 47 %(op_rd)s; 48 49 if (%(predicate_test)s) 50 { 51 %(code)s; 52 if (fault == NoFault) 53 { 54 %(op_wb)s; 55 } 56 } 57 58 return fault; 59 } 60}}; 61 62def template DataDecode {{ 63 if (machInst.opcode4 == 0) { 64 if (machInst.sField == 0) 65 return new %(class_name)sImm(machInst); 66 else 67 return new %(class_name)sImmCc(machInst); 68 } else { 69 if (machInst.sField == 0) 70 return new %(class_name)s(machInst); 71 else 72 return new %(class_name)sCc(machInst); 73 } 74}}; 75 76def template DataImmDecode {{ 77 if (machInst.sField == 0) 78 return new %(class_name)s(machInst); 79 else 80 return new %(class_name)sCc(machInst); 81}}; 82 83let {{ 84 85 calcCcCode = ''' 86 uint16_t _ic, _iv, _iz, _in; 87 88 _in = (resTemp >> 31) & 1; 89 _iz = (resTemp == 0); 90 _iv = %(ivValue)s & 1; 91 _ic = %(icValue)s & 1; 92 93 Cpsr = _in << 31 | _iz << 30 | _ic << 29 | _iv << 28 | 94 (Cpsr & 0x0FFFFFFF); 95 96 DPRINTF(Arm, "in = %%d\\n", _in); 97 DPRINTF(Arm, "iz = %%d\\n", _iz); 98 DPRINTF(Arm, "ic = %%d\\n", _ic); 99 DPRINTF(Arm, "iv = %%d\\n", _iv); 100 ''' 101 102}}; 103 104let {{ 105 def getCcCode(flagtype): 106 icReg = icImm = iv = '' 107 if flagtype == "none": 108 icReg = icImm = iv = '1' 109 elif flagtype == "add": 110 icReg = icImm = 'findCarry(32, resTemp, Rn, op2)' 111 iv = 'findOverflow(32, resTemp, Rn, op2)' 112 elif flagtype == "sub": 113 icReg = icImm ='findCarry(32, resTemp, Rn, ~op2)' 114 iv = 'findOverflow(32, resTemp, Rn, ~op2)' 115 elif flagtype == "rsb": 116 icReg = icImm = 'findCarry(32, resTemp, op2, ~Rn)' 117 iv = 'findOverflow(32, resTemp, op2, ~Rn)' 118 else: 119 icReg = 'shift_carry_rs(Rm, Rs, shift, Cpsr<29:>)' 120 icImm = 'shift_carry_imm(Rm, shift_size, shift, Cpsr<29:>)' 121 iv = 'Cpsr<28:>' 122 return (calcCcCode % {"icValue" : icReg, "ivValue" : iv}, 123 calcCcCode % {"icValue" : icImm, "ivValue" : iv}) 124 125 def getImmCcCode(flagtype): 126 ivValue = icValue = '' 127 if flagtype == "none": 128 icValue = ivValue = '1' 129 elif flagtype == "add": 130 icValue = 'findCarry(32, resTemp, Rn, rotated_imm)' 131 ivValue = 'findOverflow(32, resTemp, Rn, rotated_imm)' 132 elif flagtype == "sub": 133 icValue = 'findCarry(32, resTemp, Rn, ~rotated_imm)' 134 ivValue = 'findOverflow(32, resTemp, Rn, ~rotated_imm)' 135 elif flagtype == "rsb": 136 icValue = 'findCarry(32, resTemp, rotated_imm, ~Rn)' 137 ivValue = 'findOverflow(32, resTemp, rotated_imm, ~Rn)' 138 else: 139 icValue = '(rotate ? rotated_carry:Cpsr<29:>)' 140 ivValue = 'Cpsr<28:>' 141 return calcCcCode % vars() 142}}; 143 144def format DataOp(code, flagtype = logic) {{ 145 (regCcCode, immCcCode) = getCcCode(flagtype) 146 regCode = '''uint32_t op2 = shift_rm_rs(Rm, Rs, 147 shift, Cpsr<29:0>); 148 op2 = op2;''' + code 149 immCode = '''uint32_t op2 = shift_rm_imm(Rm, shift_size, 150 shift, Cpsr<29:0>); 151 op2 = op2;''' + code 152 regIop = InstObjParams(name, Name, 'PredIntOp', 153 {"code": regCode, 154 "predicate_test": predicateTest}) 155 immIop = InstObjParams(name, Name + "Imm", 'PredIntOp', 156 {"code": immCode, 157 "predicate_test": predicateTest}) 158 regCcIop = InstObjParams(name, Name + "Cc", 'PredIntOp', 159 {"code": regCode + regCcCode, 160 "predicate_test": predicateTest}) 161 immCcIop = InstObjParams(name, Name + "ImmCc", 'PredIntOp', 162 {"code": immCode + immCcCode, 163 "predicate_test": predicateTest}) 164 header_output = BasicDeclare.subst(regIop) + \ 165 BasicDeclare.subst(immIop) + \ 166 BasicDeclare.subst(regCcIop) + \ 167 BasicDeclare.subst(immCcIop) 168 decoder_output = BasicConstructor.subst(regIop) + \ 169 BasicConstructor.subst(immIop) + \ 170 BasicConstructor.subst(regCcIop) + \ 171 BasicConstructor.subst(immCcIop) 172 exec_output = PredOpExecute.subst(regIop) + \ 173 PredOpExecute.subst(immIop) + \ 174 PredOpExecute.subst(regCcIop) + \ 175 PredOpExecute.subst(immCcIop) 176 decode_block = DataDecode.subst(regIop) 177}}; 178 179def format DataImmOp(code, flagtype = logic) {{ 180 code += "resTemp = resTemp;" 181 iop = InstObjParams(name, Name, 'PredImmOp', 182 {"code": code, 183 "predicate_test": predicateTest}) 184 ccIop = InstObjParams(name, Name + "Cc", 'PredImmOp', 185 {"code": code + getImmCcCode(flagtype), 186 "predicate_test": predicateTest}) 187 header_output = BasicDeclare.subst(iop) + \ 188 BasicDeclare.subst(ccIop) 189 decoder_output = BasicConstructor.subst(iop) + \ 190 BasicConstructor.subst(ccIop) 191 exec_output = PredOpExecute.subst(iop) + \ 192 PredOpExecute.subst(ccIop) 193 decode_block = DataImmDecode.subst(iop) 194}}; 195 196def format PredOp(code, *opt_flags) {{ 197 iop = InstObjParams(name, Name, 'PredOp', 198 {"code": code, 199 "predicate_test": predicateTest}, 200 opt_flags) 201 header_output = BasicDeclare.subst(iop) 202 decoder_output = BasicConstructor.subst(iop) 203 decode_block = BasicDecode.subst(iop) 204 exec_output = PredOpExecute.subst(iop) 205}}; 206 207def format PredImmOp(code, *opt_flags) {{ 208 iop = InstObjParams(name, Name, 'PredImmOp', 209 {"code": code, 210 "predicate_test": predicateTest}, 211 opt_flags) 212 header_output = BasicDeclare.subst(iop) 213 decoder_output = BasicConstructor.subst(iop) 214 decode_block = BasicDecode.subst(iop) 215 exec_output = PredOpExecute.subst(iop) 216}}; 217 218def format PredImmOpCc(code, icValue, ivValue, *opt_flags) {{ 219 ccCode = calcCcCode % vars() 220 code += ccCode; 221 iop = InstObjParams(name, Name, 'PredImmOp', 222 {"code": code, 223 "cc_code": ccCode, 224 "predicate_test": predicateTest}, 225 opt_flags) 226 header_output = BasicDeclare.subst(iop) 227 decoder_output = BasicConstructor.subst(iop) 228 decode_block = BasicDecode.subst(iop) 229 exec_output = PredOpExecute.subst(iop) 230}}; 231 232def format PredIntOp(code, *opt_flags) {{ 233 new_code = ArmGenericCodeSubs(code) 234 iop = InstObjParams(name, Name, 'PredIntOp', 235 {"code": new_code, 236 "predicate_test": predicateTest}, 237 opt_flags) 238 header_output = BasicDeclare.subst(iop) 239 decoder_output = BasicConstructor.subst(iop) 240 decode_block = BasicDecode.subst(iop) 241 exec_output = PredOpExecute.subst(iop) 242}}; 243 244def format PredIntOpCc(code, icValue, ivValue, *opt_flags) {{ 245 ccCode = calcCcCode % vars() 246 code += ccCode; 247 new_code = ArmGenericCodeSubs(code) 248 iop = InstObjParams(name, Name, 'PredIntOp', 249 {"code": new_code, 250 "cc_code": ccCode, 251 "predicate_test": predicateTest}, 252 opt_flags) 253 header_output = BasicDeclare.subst(iop) 254 decoder_output = BasicConstructor.subst(iop) 255 decode_block = BasicDecode.subst(iop) 256 exec_output = PredOpExecute.subst(iop) 257}}; 258 259