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