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