fp.isa revision 6243:3a1698fbbc9f
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                if (%(predicate_test)s) {
69                    %(code)s;
70                    if (fault == NoFault) {
71                        %(op_wb)s;
72                    }
73                }
74
75                return fault;
76        }
77}};
78
79def template FloatDoubleDecode {{
80    {
81        ArmStaticInst *i = NULL;
82        switch (OPCODE_19 << 1 | OPCODE_7)
83        {
84            case 0:
85                i = (ArmStaticInst *)new %(class_name)sS(machInst);
86                break;
87            case 1:
88                i = (ArmStaticInst *)new %(class_name)sD(machInst);
89                break;
90            case 2:
91            case 3:
92            default:
93                panic("Cannot decode float/double nature of the instruction");
94        }
95        return i;
96    }
97}};
98
99// Primary format for float point operate instructions:
100def format FloatOp(code, *flags) {{
101        orig_code = code
102
103        cblk = code
104        iop = InstObjParams(name, Name, 'FPAOp',
105                            {"code": cblk,
106                             "predicate_test": predicateTest},
107                            flags)
108        header_output = BasicDeclare.subst(iop)
109        decoder_output = BasicConstructor.subst(iop)
110        exec_output = FPAExecute.subst(iop)
111
112        sng_cblk = code
113        sng_iop = InstObjParams(name, Name+'S', 'FPAOp',
114                                {"code": sng_cblk,
115                                 "predicate_test": predicateTest},
116                                flags)
117        header_output += BasicDeclare.subst(sng_iop)
118        decoder_output += BasicConstructor.subst(sng_iop)
119        exec_output += FPAExecute.subst(sng_iop)
120
121        dbl_code = re.sub(r'\.sf', '.df', orig_code)
122
123        dbl_cblk = dbl_code
124        dbl_iop = InstObjParams(name, Name+'D', 'FPAOp',
125                                {"code": dbl_cblk,
126                                 "predicate_test": predicateTest},
127                                flags)
128        header_output += BasicDeclare.subst(dbl_iop)
129        decoder_output += BasicConstructor.subst(dbl_iop)
130        exec_output += FPAExecute.subst(dbl_iop)
131
132        decode_block = FloatDoubleDecode.subst(iop)
133}};
134
135let {{
136        calcFPCcCode = '''
137        uint16_t _in, _iz, _ic, _iv;
138
139        _in = %(fReg1)s < %(fReg2)s;
140        _iz = %(fReg1)s == %(fReg2)s;
141        _ic = %(fReg1)s >= %(fReg2)s;
142        _iv = (isnan(%(fReg1)s) || isnan(%(fReg2)s)) & 1;
143
144        Cpsr = _in << 31 | _iz << 30 | _ic << 29 | _iv << 28 |
145            (Cpsr & 0x0FFFFFFF);
146        '''
147}};
148
149def format FloatCmp(fReg1, fReg2, *flags) {{
150        code = calcFPCcCode % vars()
151        iop = InstObjParams(name, Name, 'FPAOp',
152                            {"code": code,
153                             "predicate_test": predicateTest},
154                             flags)
155        header_output = BasicDeclare.subst(iop)
156        decoder_output = BasicConstructor.subst(iop)
157        decode_block = BasicDecode.subst(iop)
158        exec_output = FPAExecute.subst(iop)
159}};
160
161
162