pred.isa revision 6724:70129fdded75
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(CondCodes, 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        CondCodes =  _in << 31 | _iz << 30 | _ic << 29 | _iv << 28 |
94            (CondCodes & 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
104let {{
105    def getCcCode(flagtype):
106        icReg = icImm = iv = ''
107        if flagtype == "none":
108            icReg = icImm = 'CondCodes<29:>'
109            iv = 'CondCodes<28:>'
110        elif flagtype == "add":
111            icReg = icImm = 'findCarry(32, resTemp, Rn, op2)'
112            iv = 'findOverflow(32, resTemp, Rn, op2)'
113        elif flagtype == "sub":
114            icReg = icImm ='findCarry(32, resTemp, Rn, ~op2)'
115            iv = 'findOverflow(32, resTemp, Rn, ~op2)'
116        elif flagtype == "rsb":
117            icReg = icImm = 'findCarry(32, resTemp, op2, ~Rn)'
118            iv = 'findOverflow(32, resTemp, op2, ~Rn)'
119        else:
120            icReg = 'shift_carry_rs(Rm, Rs, shift, CondCodes<29:>)'
121            icImm = 'shift_carry_imm(Rm, shift_size, shift, CondCodes<29:>)'
122            iv = 'CondCodes<28:>'
123        return (calcCcCode % {"icValue" : icReg, "ivValue" : iv},
124                calcCcCode % {"icValue" : icImm, "ivValue" : iv})
125
126    def getImmCcCode(flagtype):
127        ivValue = icValue = ''
128        if flagtype == "none":
129            icValue = 'CondCodes<29:>'
130            ivValue = 'CondCodes<28:>'
131        elif flagtype == "add":
132            icValue = 'findCarry(32, resTemp, Rn, rotated_imm)'
133            ivValue = 'findOverflow(32, resTemp, Rn, rotated_imm)'
134        elif flagtype == "sub":
135            icValue = 'findCarry(32, resTemp, Rn, ~rotated_imm)'
136            ivValue = 'findOverflow(32, resTemp, Rn, ~rotated_imm)'
137        elif flagtype == "rsb":
138            icValue = 'findCarry(32, resTemp, rotated_imm, ~Rn)'
139            ivValue = 'findOverflow(32, resTemp, rotated_imm, ~Rn)'
140        else:
141            icValue = '(rotate ? rotated_carry:CondCodes<29:>)'
142            ivValue = 'CondCodes<28:>'
143        return calcCcCode % vars()
144}};
145
146def format DataOp(code, flagtype = logic) {{
147    (regCcCode, immCcCode) = getCcCode(flagtype)
148    regCode = '''uint32_t op2 = shift_rm_rs(Rm, Rs,
149                                            shift, CondCodes<29:0>);
150                 op2 = op2;''' + code
151    immCode = '''uint32_t op2 = shift_rm_imm(Rm, shift_size,
152                                             shift, CondCodes<29:0>);
153                 op2 = op2;''' + code
154    regIop = InstObjParams(name, Name, 'PredIntOp',
155                           {"code": regCode,
156                            "predicate_test": predicateTest})
157    immIop = InstObjParams(name, Name + "Imm", 'PredIntOp',
158                           {"code": immCode,
159                            "predicate_test": predicateTest})
160    regCcIop = InstObjParams(name, Name + "Cc", 'PredIntOp',
161                             {"code": regCode + regCcCode,
162                              "predicate_test": predicateTest})
163    immCcIop = InstObjParams(name, Name + "ImmCc", 'PredIntOp',
164                             {"code": immCode + immCcCode,
165                              "predicate_test": predicateTest})
166    header_output = BasicDeclare.subst(regIop) + \
167                    BasicDeclare.subst(immIop) + \
168                    BasicDeclare.subst(regCcIop) + \
169                    BasicDeclare.subst(immCcIop)
170    decoder_output = BasicConstructor.subst(regIop) + \
171                     BasicConstructor.subst(immIop) + \
172                     BasicConstructor.subst(regCcIop) + \
173                     BasicConstructor.subst(immCcIop)
174    exec_output = PredOpExecute.subst(regIop) + \
175                  PredOpExecute.subst(immIop) + \
176                  PredOpExecute.subst(regCcIop) + \
177                  PredOpExecute.subst(immCcIop)
178    decode_block = DataDecode.subst(regIop)
179}};
180
181def format DataImmOp(code, flagtype = logic) {{
182    code += "resTemp = resTemp;"
183    iop = InstObjParams(name, Name, 'PredImmOp',
184                        {"code": code,
185                         "predicate_test": predicateTest})
186    ccIop = InstObjParams(name, Name + "Cc", 'PredImmOp',
187                          {"code": code + getImmCcCode(flagtype),
188                           "predicate_test": predicateTest})
189    header_output = BasicDeclare.subst(iop) + \
190                    BasicDeclare.subst(ccIop)
191    decoder_output = BasicConstructor.subst(iop) + \
192                     BasicConstructor.subst(ccIop)
193    exec_output = PredOpExecute.subst(iop) + \
194                  PredOpExecute.subst(ccIop)
195    decode_block = DataImmDecode.subst(iop)
196}};
197
198def format PredOp(code, *opt_flags) {{
199    iop = InstObjParams(name, Name, 'PredOp',
200                        {"code": code,
201                         "predicate_test": predicateTest},
202                        opt_flags)
203    header_output = BasicDeclare.subst(iop)
204    decoder_output = BasicConstructor.subst(iop)
205    decode_block = BasicDecode.subst(iop)
206    exec_output = PredOpExecute.subst(iop)
207}};
208
209def format PredImmOp(code, *opt_flags) {{
210    iop = InstObjParams(name, Name, 'PredImmOp',
211                        {"code": code,
212                         "predicate_test": predicateTest},
213                        opt_flags)
214    header_output = BasicDeclare.subst(iop)
215    decoder_output = BasicConstructor.subst(iop)
216    decode_block = BasicDecode.subst(iop)
217    exec_output = PredOpExecute.subst(iop)
218}};
219
220def format PredImmOpCc(code, icValue, ivValue, *opt_flags) {{
221    ccCode = calcCcCode % vars()
222    code += ccCode;
223    iop = InstObjParams(name, Name, 'PredImmOp',
224                        {"code": code,
225                         "cc_code": ccCode,
226                         "predicate_test": predicateTest},
227                        opt_flags)
228    header_output = BasicDeclare.subst(iop)
229    decoder_output = BasicConstructor.subst(iop)
230    decode_block = BasicDecode.subst(iop)
231    exec_output = PredOpExecute.subst(iop)
232}};
233
234def format PredIntOp(code, *opt_flags) {{
235    new_code = ArmGenericCodeSubs(code)
236    iop = InstObjParams(name, Name, 'PredIntOp',
237                        {"code": new_code,
238                         "predicate_test": predicateTest},
239                        opt_flags)
240    header_output = BasicDeclare.subst(iop)
241    decoder_output = BasicConstructor.subst(iop)
242    decode_block = BasicDecode.subst(iop)
243    exec_output = PredOpExecute.subst(iop)
244}};
245
246def format PredIntOpCc(code, icValue, ivValue, *opt_flags) {{
247    ccCode = calcCcCode % vars()
248    code += ccCode;
249    new_code = ArmGenericCodeSubs(code)
250    iop = InstObjParams(name, Name, 'PredIntOp',
251                        {"code": new_code,
252                         "cc_code": ccCode,
253                         "predicate_test": predicateTest},
254                        opt_flags)
255    header_output = BasicDeclare.subst(iop)
256    decoder_output = BasicConstructor.subst(iop)
257    decode_block = BasicDecode.subst(iop)
258    exec_output = PredOpExecute.subst(iop)
259}};
260
261