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