branch.isa (4253:65a2461fcfc2) branch.isa (5091:662c1d7b4795)
1// Copyright (c) 2006-2007 The Regents of The University of Michigan
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met: redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer;
8// redistributions in binary form must reproduce the above copyright

--- 169 unchanged lines hidden (view full) ---

178 else
179 ccprintf(response, ">");
180 }
181
182 return response.str();
183 }
184}};
185
1// Copyright (c) 2006-2007 The Regents of The University of Michigan
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met: redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer;
8// redistributions in binary form must reproduce the above copyright

--- 169 unchanged lines hidden (view full) ---

178 else
179 ccprintf(response, ">");
180 }
181
182 return response.str();
183 }
184}};
185
186def template BranchExecute {{
186def template JumpExecute {{
187 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
188 Trace::InstRecord *traceData) const
189 {
190 //Attempt to execute the instruction
191 Fault fault = NoFault;
192
193 %(op_decl)s;
194 %(op_rd)s;

--- 6 unchanged lines hidden (view full) ---

201 //Write the resulting state to the execution context
202 %(op_wb)s;
203 }
204
205 return fault;
206 }
207}};
208
187 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
188 Trace::InstRecord *traceData) const
189 {
190 //Attempt to execute the instruction
191 Fault fault = NoFault;
192
193 %(op_decl)s;
194 %(op_rd)s;

--- 6 unchanged lines hidden (view full) ---

201 //Write the resulting state to the execution context
202 %(op_wb)s;
203 }
204
205 return fault;
206 }
207}};
208
209let {{
210 handle_annul = '''
211 {
212 if(A)
209def template BranchExecute {{
210 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
211 Trace::InstRecord *traceData) const
213 {
212 {
214 NNPC = NPC + 8;
215 NPC = NPC + 4;
213 //Attempt to execute the instruction
214 Fault fault = NoFault;
215
216 %(op_decl)s;
217 %(op_rd)s;
218
219 if (%(cond)s) {
220 %(code)s;
221 } else {
222 %(fail)s;
223 }
224
225 if(fault == NoFault)
226 {
227 //Write the resulting state to the execution context
228 %(op_wb)s;
229 }
230
231 return fault;
216 }
232 }
217 else
218 {
219 NPC = NPC;
220 NNPC = NNPC;
221 }
222 }'''
223}};
224
233}};
234
235def template BranchDecode {{
236 if (A)
237 return new %(class_name)sAnnul("%(mnemonic)s,a", machInst);
238 else
239 return new %(class_name)s("%(mnemonic)s", machInst);
240}};
241
225// Primary format for branch instructions:
226def format Branch(code, *opt_flags) {{
242// Primary format for branch instructions:
243def format Branch(code, *opt_flags) {{
227 (usesImm, code, immCode,
228 rString, iString) = splitOutImm(code)
229 iop = InstObjParams(name, Name, 'Branch', code, opt_flags)
230 header_output = BasicDeclare.subst(iop)
231 decoder_output = BasicConstructor.subst(iop)
244 (usesImm, code, immCode,
245 rString, iString) = splitOutImm(code)
246 iop = InstObjParams(name, Name, 'Branch', code, opt_flags)
247 header_output = BasicDeclare.subst(iop)
248 decoder_output = BasicConstructor.subst(iop)
249 exec_output = JumpExecute.subst(iop)
250 if usesImm:
251 imm_iop = InstObjParams(name, Name + 'Imm', 'BranchImm' + iString,
252 immCode, opt_flags)
253 header_output += BasicDeclare.subst(imm_iop)
254 decoder_output += BasicConstructor.subst(imm_iop)
255 exec_output += JumpExecute.subst(imm_iop)
256 decode_block = ROrImmDecode.subst(iop)
257 else:
258 decode_block = BasicDecode.subst(iop)
259}};
260
261let {{
262 def doBranch(name, Name, base, cond,
263 code, annul_code, fail, annul_fail, opt_flags):
264 iop = InstObjParams(name, Name, base,
265 {"code": code,
266 "fail": fail,
267 "cond": cond
268 },
269 opt_flags)
270 header_output = BasicDeclareWithMnemonic.subst(iop)
271 decoder_output = BasicConstructorWithMnemonic.subst(iop)
232 exec_output = BranchExecute.subst(iop)
272 exec_output = BranchExecute.subst(iop)
233 if usesImm:
234 imm_iop = InstObjParams(name, Name + 'Imm', 'BranchImm' + iString,
235 immCode, opt_flags)
236 header_output += BasicDeclare.subst(imm_iop)
237 decoder_output += BasicConstructor.subst(imm_iop)
238 exec_output += BranchExecute.subst(imm_iop)
239 decode_block = ROrImmDecode.subst(iop)
273 if annul_code == "None":
274 decode_block = BasicDecodeWithMnemonic.subst(iop)
240 else:
275 else:
241 decode_block = BasicDecode.subst(iop)
276 decode_block = BranchDecode.subst(iop)
277
278 if annul_code != "None":
279 iop = InstObjParams(name + ',a', Name + 'Annul', base,
280 {"code": annul_code,
281 "fail": annul_fail,
282 "cond": cond
283 },
284 opt_flags)
285 header_output += BasicDeclareWithMnemonic.subst(iop)
286 decoder_output += BasicConstructorWithMnemonic.subst(iop)
287 exec_output += BranchExecute.subst(iop)
288 return (header_output, decoder_output, exec_output, decode_block)
289
290 def doCondBranch(name, Name, base, cond, code, opt_flags):
291 return doBranch(name, Name, base, cond, code, code,
292 'NPC = NPC; NNPC = NNPC;',
293 'NNPC = NPC + 8; NPC = NPC + 4',
294 opt_flags)
295
296 def doUncondBranch(name, Name, base, code, annul_code, opt_flags):
297 return doBranch(name, Name, base, "true", code, annul_code,
298 ";", ";", opt_flags)
299
300 default_branch_code = "NNPC = xc->readPC() + disp;"
242}};
243
301}};
302
244// Primary format for branch instructions:
245def format BranchN(bits, code, *opt_flags) {{
246 code = re.sub(r'handle_annul', handle_annul, code)
247 new_opt_flags = []
248 for flag in opt_flags:
249 if flag == ',a':
250 name += ',a'
251 Name += 'Annul'
252 else:
253 new_opt_flags += flag
254 iop = InstObjParams(name, Name, "BranchNBits<%d>" % bits, code, new_opt_flags)
255 header_output = BasicDeclare.subst(iop)
256 decoder_output = BasicConstructor.subst(iop)
257 exec_output = BranchExecute.subst(iop)
258 decode_block = BasicDecode.subst(iop)
303// Format for branch instructions with n bit displacements:
304def format BranchN(bits, code=default_branch_code,
305 test=None, annul_code=None, *opt_flags) {{
306 if code == "default_branch_code":
307 code = default_branch_code
308 if test != "None":
309 (header_output,
310 decoder_output,
311 exec_output,
312 decode_block) = doCondBranch(name, Name,
313 "BranchNBits<%d>" % bits, test, code, opt_flags)
314 else:
315 (header_output,
316 decoder_output,
317 exec_output,
318 decode_block) = doUncondBranch(name, Name,
319 "BranchNBits<%d>" % bits, code, annul_code, opt_flags)
259}};
260
320}};
321
261// Primary format for branch instructions:
262def format BranchSplit(code, *opt_flags) {{
263 code = re.sub(r'handle_annul', handle_annul, code)
264 iop = InstObjParams(name, Name, 'BranchSplit', code, opt_flags)
265 header_output = BasicDeclare.subst(iop)
266 decoder_output = BasicConstructor.subst(iop)
267 exec_output = BranchExecute.subst(iop)
268 decode_block = BasicDecode.subst(iop)
322// Format for branch instructions with split displacements:
323def format BranchSplit(code=default_branch_code,
324 test=None, annul_code=None, *opt_flags) {{
325 if code == "default_branch_code":
326 code = default_branch_code
327 if test != "None":
328 (header_output,
329 decoder_output,
330 exec_output,
331 decode_block) = doCondBranch(name, Name,
332 "BranchSplit", test, code, opt_flags)
333 else:
334 (header_output,
335 decoder_output,
336 exec_output,
337 decode_block) = doUncondBranch(name, Name,
338 "BranchSplit", code, annul_code, opt_flags)
269}};
270
339}};
340