pred.isa revision 6272:fa79e8f9ab41
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
104def format DataOp(code, icValue, ivValue) {{
105    regCode = '''uint32_t op2 = shift_rm_rs(Rm, Rs,
106                                            shift, Cpsr<29:0>);
107                 op2 = op2;''' + code
108    immCode = '''uint32_t op2 = shift_rm_imm(Rm, shift_size,
109                                             shift, Cpsr<29:0>);
110                 op2 = op2;''' + code
111    regIop = InstObjParams(name, Name, 'PredIntOp',
112                           {"code": regCode,
113                            "predicate_test": predicateTest})
114    immIop = InstObjParams(name, Name + "Imm", 'PredIntOp',
115                           {"code": immCode,
116                            "predicate_test": predicateTest})
117    regCcIop = InstObjParams(name, Name + "Cc", 'PredIntOp',
118                             {"code": regCode + calcCcCode % vars(),
119                              "predicate_test": predicateTest})
120    immCcIop = InstObjParams(name, Name + "ImmCc", 'PredIntOp',
121                             {"code": immCode + calcCcCode % vars(),
122                              "predicate_test": predicateTest})
123    header_output = BasicDeclare.subst(regIop) + \
124                    BasicDeclare.subst(immIop) + \
125                    BasicDeclare.subst(regCcIop) + \
126                    BasicDeclare.subst(immCcIop)
127    decoder_output = BasicConstructor.subst(regIop) + \
128                     BasicConstructor.subst(immIop) + \
129                     BasicConstructor.subst(regCcIop) + \
130                     BasicConstructor.subst(immCcIop)
131    exec_output = PredOpExecute.subst(regIop) + \
132                  PredOpExecute.subst(immIop) + \
133                  PredOpExecute.subst(regCcIop) + \
134                  PredOpExecute.subst(immCcIop)
135    decode_block = DataDecode.subst(regIop)
136}};
137
138def format DataImmOp(code, icValue, ivValue) {{
139    code += "resTemp = resTemp;"
140    iop = InstObjParams(name, Name, 'PredImmOp',
141                        {"code": code,
142                         "predicate_test": predicateTest})
143    ccIop = InstObjParams(name, Name + "Cc", 'PredImmOp',
144                          {"code": code + calcCcCode % vars(),
145                           "predicate_test": predicateTest})
146    header_output = BasicDeclare.subst(iop) + \
147                    BasicDeclare.subst(ccIop)
148    decoder_output = BasicConstructor.subst(iop) + \
149                     BasicConstructor.subst(ccIop)
150    exec_output = PredOpExecute.subst(iop) + \
151                  PredOpExecute.subst(ccIop)
152    decode_block = DataImmDecode.subst(iop)
153}};
154
155def format PredOp(code, *opt_flags) {{
156    iop = InstObjParams(name, Name, 'PredOp',
157                        {"code": code,
158                         "predicate_test": predicateTest},
159                        opt_flags)
160    header_output = BasicDeclare.subst(iop)
161    decoder_output = BasicConstructor.subst(iop)
162    decode_block = BasicDecode.subst(iop)
163    exec_output = PredOpExecute.subst(iop)
164}};
165
166def format PredImmOp(code, *opt_flags) {{
167    iop = InstObjParams(name, Name, 'PredImmOp',
168                        {"code": code,
169                         "predicate_test": predicateTest},
170                        opt_flags)
171    header_output = BasicDeclare.subst(iop)
172    decoder_output = BasicConstructor.subst(iop)
173    decode_block = BasicDecode.subst(iop)
174    exec_output = PredOpExecute.subst(iop)
175}};
176
177def format PredImmOpCc(code, icValue, ivValue, *opt_flags) {{
178    ccCode = calcCcCode % vars()
179    code += ccCode;
180    iop = InstObjParams(name, Name, 'PredImmOp',
181                        {"code": code,
182                         "cc_code": ccCode,
183                         "predicate_test": predicateTest},
184                        opt_flags)
185    header_output = BasicDeclare.subst(iop)
186    decoder_output = BasicConstructor.subst(iop)
187    decode_block = BasicDecode.subst(iop)
188    exec_output = PredOpExecute.subst(iop)
189}};
190
191def format PredIntOp(code, *opt_flags) {{
192    new_code = ArmGenericCodeSubs(code)
193    iop = InstObjParams(name, Name, 'PredIntOp',
194                        {"code": new_code,
195                         "predicate_test": predicateTest},
196                        opt_flags)
197    header_output = BasicDeclare.subst(iop)
198    decoder_output = BasicConstructor.subst(iop)
199    decode_block = BasicDecode.subst(iop)
200    exec_output = PredOpExecute.subst(iop)
201}};
202
203def format PredIntOpCc(code, icValue, ivValue, *opt_flags) {{
204    ccCode = calcCcCode % vars()
205    code += ccCode;
206    new_code = ArmGenericCodeSubs(code)
207    iop = InstObjParams(name, Name, 'PredIntOp',
208                        {"code": new_code,
209                         "cc_code": ccCode,
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
218