fp.isa revision 6724
16019Shines@cs.fsu.edu// -*- mode:c++ -*-
26019Shines@cs.fsu.edu
36019Shines@cs.fsu.edu// Copyright (c) 2007-2008 The Florida State University
46019Shines@cs.fsu.edu// All rights reserved.
56019Shines@cs.fsu.edu//
66019Shines@cs.fsu.edu// Redistribution and use in source and binary forms, with or without
76019Shines@cs.fsu.edu// modification, are permitted provided that the following conditions are
86019Shines@cs.fsu.edu// met: redistributions of source code must retain the above copyright
96019Shines@cs.fsu.edu// notice, this list of conditions and the following disclaimer;
106019Shines@cs.fsu.edu// redistributions in binary form must reproduce the above copyright
116019Shines@cs.fsu.edu// notice, this list of conditions and the following disclaimer in the
126019Shines@cs.fsu.edu// documentation and/or other materials provided with the distribution;
136019Shines@cs.fsu.edu// neither the name of the copyright holders nor the names of its
146019Shines@cs.fsu.edu// contributors may be used to endorse or promote products derived from
156019Shines@cs.fsu.edu// this software without specific prior written permission.
166019Shines@cs.fsu.edu//
176019Shines@cs.fsu.edu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
186019Shines@cs.fsu.edu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
196019Shines@cs.fsu.edu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
206019Shines@cs.fsu.edu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
216019Shines@cs.fsu.edu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
226019Shines@cs.fsu.edu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
236019Shines@cs.fsu.edu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
246019Shines@cs.fsu.edu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
256019Shines@cs.fsu.edu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
266019Shines@cs.fsu.edu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
276019Shines@cs.fsu.edu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
286019Shines@cs.fsu.edu//
296019Shines@cs.fsu.edu// Authors: Stephen Hines
306019Shines@cs.fsu.edu
316019Shines@cs.fsu.edu////////////////////////////////////////////////////////////////////
326019Shines@cs.fsu.edu//
336019Shines@cs.fsu.edu// Floating Point operate instructions
346019Shines@cs.fsu.edu//
356019Shines@cs.fsu.edu
366019Shines@cs.fsu.edudef template FPAExecute {{
376019Shines@cs.fsu.edu        Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, Trace::InstRecord *traceData) const
386019Shines@cs.fsu.edu        {
396019Shines@cs.fsu.edu                Fault fault = NoFault;
406019Shines@cs.fsu.edu
416019Shines@cs.fsu.edu                %(fp_enable_check)s;
426019Shines@cs.fsu.edu
436019Shines@cs.fsu.edu                %(op_decl)s;
446019Shines@cs.fsu.edu                %(op_rd)s;
456019Shines@cs.fsu.edu
466243Sgblack@eecs.umich.edu                if (%(predicate_test)s) {
476243Sgblack@eecs.umich.edu                    %(code)s;
486243Sgblack@eecs.umich.edu                    if (fault == NoFault) {
496243Sgblack@eecs.umich.edu                        %(op_wb)s;
506243Sgblack@eecs.umich.edu                    }
516019Shines@cs.fsu.edu                }
526019Shines@cs.fsu.edu
536019Shines@cs.fsu.edu                return fault;
546019Shines@cs.fsu.edu        }
556019Shines@cs.fsu.edu}};
566019Shines@cs.fsu.edu
576019Shines@cs.fsu.edudef template FloatDoubleDecode {{
586019Shines@cs.fsu.edu    {
596019Shines@cs.fsu.edu        ArmStaticInst *i = NULL;
606019Shines@cs.fsu.edu        switch (OPCODE_19 << 1 | OPCODE_7)
616019Shines@cs.fsu.edu        {
626019Shines@cs.fsu.edu            case 0:
636019Shines@cs.fsu.edu                i = (ArmStaticInst *)new %(class_name)sS(machInst);
646019Shines@cs.fsu.edu                break;
656019Shines@cs.fsu.edu            case 1:
666019Shines@cs.fsu.edu                i = (ArmStaticInst *)new %(class_name)sD(machInst);
676019Shines@cs.fsu.edu                break;
686019Shines@cs.fsu.edu            case 2:
696019Shines@cs.fsu.edu            case 3:
706019Shines@cs.fsu.edu            default:
716019Shines@cs.fsu.edu                panic("Cannot decode float/double nature of the instruction");
726019Shines@cs.fsu.edu        }
736019Shines@cs.fsu.edu        return i;
746019Shines@cs.fsu.edu    }
756019Shines@cs.fsu.edu}};
766019Shines@cs.fsu.edu
776019Shines@cs.fsu.edu// Primary format for float point operate instructions:
786019Shines@cs.fsu.edudef format FloatOp(code, *flags) {{
796019Shines@cs.fsu.edu        orig_code = code
806019Shines@cs.fsu.edu
816019Shines@cs.fsu.edu        cblk = code
826252Sgblack@eecs.umich.edu        iop = InstObjParams(name, Name, 'PredOp',
836243Sgblack@eecs.umich.edu                            {"code": cblk,
846243Sgblack@eecs.umich.edu                             "predicate_test": predicateTest},
856243Sgblack@eecs.umich.edu                            flags)
866019Shines@cs.fsu.edu        header_output = BasicDeclare.subst(iop)
876019Shines@cs.fsu.edu        decoder_output = BasicConstructor.subst(iop)
886019Shines@cs.fsu.edu        exec_output = FPAExecute.subst(iop)
896019Shines@cs.fsu.edu
906019Shines@cs.fsu.edu        sng_cblk = code
916252Sgblack@eecs.umich.edu        sng_iop = InstObjParams(name, Name+'S', 'PredOp',
926243Sgblack@eecs.umich.edu                                {"code": sng_cblk,
936243Sgblack@eecs.umich.edu                                 "predicate_test": predicateTest},
946243Sgblack@eecs.umich.edu                                flags)
956019Shines@cs.fsu.edu        header_output += BasicDeclare.subst(sng_iop)
966019Shines@cs.fsu.edu        decoder_output += BasicConstructor.subst(sng_iop)
976019Shines@cs.fsu.edu        exec_output += FPAExecute.subst(sng_iop)
986019Shines@cs.fsu.edu
996019Shines@cs.fsu.edu        dbl_code = re.sub(r'\.sf', '.df', orig_code)
1006019Shines@cs.fsu.edu
1016019Shines@cs.fsu.edu        dbl_cblk = dbl_code
1026252Sgblack@eecs.umich.edu        dbl_iop = InstObjParams(name, Name+'D', 'PredOp',
1036243Sgblack@eecs.umich.edu                                {"code": dbl_cblk,
1046243Sgblack@eecs.umich.edu                                 "predicate_test": predicateTest},
1056243Sgblack@eecs.umich.edu                                flags)
1066019Shines@cs.fsu.edu        header_output += BasicDeclare.subst(dbl_iop)
1076019Shines@cs.fsu.edu        decoder_output += BasicConstructor.subst(dbl_iop)
1086019Shines@cs.fsu.edu        exec_output += FPAExecute.subst(dbl_iop)
1096019Shines@cs.fsu.edu
1106019Shines@cs.fsu.edu        decode_block = FloatDoubleDecode.subst(iop)
1116019Shines@cs.fsu.edu}};
1126019Shines@cs.fsu.edu
1136019Shines@cs.fsu.edulet {{
1146019Shines@cs.fsu.edu        calcFPCcCode = '''
1156019Shines@cs.fsu.edu        uint16_t _in, _iz, _ic, _iv;
1166019Shines@cs.fsu.edu
1176019Shines@cs.fsu.edu        _in = %(fReg1)s < %(fReg2)s;
1186019Shines@cs.fsu.edu        _iz = %(fReg1)s == %(fReg2)s;
1196019Shines@cs.fsu.edu        _ic = %(fReg1)s >= %(fReg2)s;
1206019Shines@cs.fsu.edu        _iv = (isnan(%(fReg1)s) || isnan(%(fReg2)s)) & 1;
1216019Shines@cs.fsu.edu
1226724Sgblack@eecs.umich.edu        CondCodes = _in << 31 | _iz << 30 | _ic << 29 | _iv << 28 |
1236724Sgblack@eecs.umich.edu            (CondCodes & 0x0FFFFFFF);
1246019Shines@cs.fsu.edu        '''
1256019Shines@cs.fsu.edu}};
1266019Shines@cs.fsu.edu
1276019Shines@cs.fsu.edudef format FloatCmp(fReg1, fReg2, *flags) {{
1286019Shines@cs.fsu.edu        code = calcFPCcCode % vars()
1296252Sgblack@eecs.umich.edu        iop = InstObjParams(name, Name, 'PredOp',
1306243Sgblack@eecs.umich.edu                            {"code": code,
1316243Sgblack@eecs.umich.edu                             "predicate_test": predicateTest},
1326243Sgblack@eecs.umich.edu                             flags)
1336019Shines@cs.fsu.edu        header_output = BasicDeclare.subst(iop)
1346019Shines@cs.fsu.edu        decoder_output = BasicConstructor.subst(iop)
1356019Shines@cs.fsu.edu        decode_block = BasicDecode.subst(iop)
1366019Shines@cs.fsu.edu        exec_output = FPAExecute.subst(iop)
1376019Shines@cs.fsu.edu}};
1386019Shines@cs.fsu.edu
1396019Shines@cs.fsu.edu
140