| 1 | # |
| 2 | # collection of utility functions |
| 3 | # |
| 4 | |
| 5 | pfeSim = None |
| 6 | |
| 7 | def initSamUtility(sim): |
| 8 | """ |
| 9 | this function must be called first before other functions in this file |
| 10 | can be used. |
| 11 | """ |
| 12 | global pfeSim |
| 13 | pfeSim = sim |
| 14 | |
| 15 | |
| 16 | def lstmode(on=None): |
| 17 | """ |
| 18 | set display mode: |
| 19 | 0 - silent mode |
| 20 | 1 - display instr & register delta |
| 21 | 2 - display instr |
| 22 | """ |
| 23 | global pfeSim |
| 24 | for s in pfeSim.s: |
| 25 | s.lstmode(on) |
| 26 | |
| 27 | |
| 28 | def stepx(sid=[-1], n=1, d=1): |
| 29 | """ |
| 30 | execute instructions among strands in round-rabin order |
| 31 | sid: the strands to be included in the execution, -1 means all strands |
| 32 | n: number of instructions to be executed per strand |
| 33 | d: number of instructions to be executed per iteration |
| 34 | """ |
| 35 | global pfeSim |
| 36 | ss = [] |
| 37 | if -1 in sid: |
| 38 | # include all strands |
| 39 | ss = pfeSim.s |
| 40 | else: |
| 41 | # otherwise only selected strand(s) |
| 42 | for id in sid: |
| 43 | ss.append(pfeSim.s[id]) |
| 44 | while n > d: |
| 45 | for s in ss: |
| 46 | brk = s.step(d) |
| 47 | if brk > 0: |
| 48 | # this strand hits a breakpoint, stop execution, |
| 49 | # return remaining instruction count |
| 50 | return n-(d-brk) |
| 51 | n -= d |
| 52 | for s in ss: |
| 53 | brk = s.step(n) |
| 54 | if brk > 0: |
| 55 | # this strand hits a breakpoint, stop execution, |
| 56 | # return remaining instruction count |
| 57 | return brk |