fp.isa revision 6242:1cee707c1228
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// Floating Point operate instructions 34// 35 36output header {{ 37 38 /** 39 * Base class for FP operations. 40 */ 41 class FPAOp : public PredOp 42 { 43 protected: 44 45 /// Constructor 46 FPAOp(const char *mnem, MachInst _machInst, OpClass __opClass) : PredOp(mnem, _machInst, __opClass) 47 { 48 } 49 50 //std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const; 51 }; 52 53}}; 54 55output exec {{ 56}}; 57 58def template FPAExecute {{ 59 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, Trace::InstRecord *traceData) const 60 { 61 Fault fault = NoFault; 62 63 %(fp_enable_check)s; 64 65 %(op_decl)s; 66 %(op_rd)s; 67 68 %(code)s; 69 70 if (testPredicate(xc->readMiscReg(ArmISA::MISCREG_CPSR), condCode) && 71 fault == NoFault) 72 { 73 %(op_wb)s; 74 } 75 76 return fault; 77 } 78}}; 79 80def template FloatDoubleDecode {{ 81 { 82 ArmStaticInst *i = NULL; 83 switch (OPCODE_19 << 1 | OPCODE_7) 84 { 85 case 0: 86 i = (ArmStaticInst *)new %(class_name)sS(machInst); 87 break; 88 case 1: 89 i = (ArmStaticInst *)new %(class_name)sD(machInst); 90 break; 91 case 2: 92 case 3: 93 default: 94 panic("Cannot decode float/double nature of the instruction"); 95 } 96 return i; 97 } 98}}; 99 100// Primary format for float point operate instructions: 101def format FloatOp(code, *flags) {{ 102 orig_code = code 103 104 cblk = code 105 iop = InstObjParams(name, Name, 'FPAOp', cblk, flags) 106 header_output = BasicDeclare.subst(iop) 107 decoder_output = BasicConstructor.subst(iop) 108 exec_output = FPAExecute.subst(iop) 109 110 sng_cblk = code 111 sng_iop = InstObjParams(name, Name+'S', 'FPAOp', sng_cblk, flags) 112 header_output += BasicDeclare.subst(sng_iop) 113 decoder_output += BasicConstructor.subst(sng_iop) 114 exec_output += FPAExecute.subst(sng_iop) 115 116 dbl_code = re.sub(r'\.sf', '.df', orig_code) 117 118 dbl_cblk = dbl_code 119 dbl_iop = InstObjParams(name, Name+'D', 'FPAOp', dbl_cblk, flags) 120 header_output += BasicDeclare.subst(dbl_iop) 121 decoder_output += BasicConstructor.subst(dbl_iop) 122 exec_output += FPAExecute.subst(dbl_iop) 123 124 decode_block = FloatDoubleDecode.subst(iop) 125}}; 126 127let {{ 128 calcFPCcCode = ''' 129 uint16_t _in, _iz, _ic, _iv; 130 131 _in = %(fReg1)s < %(fReg2)s; 132 _iz = %(fReg1)s == %(fReg2)s; 133 _ic = %(fReg1)s >= %(fReg2)s; 134 _iv = (isnan(%(fReg1)s) || isnan(%(fReg2)s)) & 1; 135 136 Cpsr = _in << 31 | _iz << 30 | _ic << 29 | _iv << 28 | 137 (Cpsr & 0x0FFFFFFF); 138 ''' 139}}; 140 141def format FloatCmp(fReg1, fReg2, *flags) {{ 142 code = calcFPCcCode % vars() 143 iop = InstObjParams(name, Name, 'FPAOp', code, flags) 144 header_output = BasicDeclare.subst(iop) 145 decoder_output = BasicConstructor.subst(iop) 146 decode_block = BasicDecode.subst(iop) 147 exec_output = FPAExecute.subst(iop) 148}}; 149 150 151