Skip to content

Commit

Permalink
Merge pull request #44 from slothy-optimizer/visualization_fixes
Browse files Browse the repository at this point in the history
Improve visualization in `visualize_expected_performance` config
  • Loading branch information
hanno-becker authored Mar 27, 2024
2 parents 72d4e16 + 4fe7639 commit 71ad977
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions slothy/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ def _get_code(self, visualize_reordering):
d = self.config.placeholder_char

def gen_visualized_code_perm():
yield SourceLine("").set_comment("----- original position ---->")
for i in range(self.codesize_with_bubbles):
p = ri.get(i, None)
if p is None:
Expand All @@ -439,8 +440,29 @@ def gen_visualized_code_perm():
vis = d * p + c + d * (self.codesize - p - 1)
yield s.copy().set_length(fixlen).set_comment(vis)

def center_str_fixlen(txt, fixlen, char='-'):
txt = ' ' + txt + ' '
l = min(len(txt), fixlen)
lpad = (fixlen - l) // 2
rpad = (fixlen - l) - lpad
return char * lpad + txt + char * rpad

def gen_visualized_code_perf():
for i in range(self.codesize_with_bubbles):
cs = self.codesize_with_bubbles
if cs == 0:
return
cycles = self.cycles
block_size = 25
cycle_blocks = math.ceil(cycles/block_size)

legend0 = center_str_fixlen('expected cycle count', cycles - 1, '-') + '>'
legend1 = ''.join([str(i*block_size).ljust(block_size) for i in range(cycle_blocks)])
legend2 = (('|' + '-' * (block_size - 1))) * (cycle_blocks - 1)
legend2 = legend2 + '|' + '-' * max(cycles % block_size - 1, 0)
yield SourceLine("").set_comment(legend0).set_length(fixlen)
yield SourceLine("").set_comment(legend1).set_length(fixlen)
yield SourceLine("").set_comment(legend2).set_length(fixlen)
for i in range(cs):
p = ri.get(i, None)
if p is None:
continue
Expand All @@ -451,7 +473,7 @@ def gen_visualized_code_perf():
elif self.is_post(p):
c = late_char
cc = i // self.config.target.issue_rate
vis = d * cc + c + d * (self.cycles - cc - 1)
vis = d * cc + c + d * (cycles - cc - 1)
yield s.copy().set_length(fixlen).set_comment(vis)

def gen_visualized_code():
Expand All @@ -461,9 +483,16 @@ def gen_visualized_code():
yield from gen_visualized_code_perm()

res = []
res.append(SourceLine("").set_comment(f"Instructions: {self.codesize}"))
res.append(SourceLine("").set_comment(f"Expected cycles: {self.cycles}"))
res.append(SourceLine("").set_comment(f"Expected IPC: {self.ipc}"))
res.append(SourceLine("") \
.set_comment(f"Instructions: {self.codesize}") \
.set_length(fixlen))
res.append(SourceLine("") \
.set_comment(f"Expected cycles: {self.cycles}") \
.set_length(fixlen))
res.append(SourceLine("") \
.set_comment(f"Expected IPC: {self.ipc:.2f}") \
.set_length(fixlen))

res += list(gen_visualized_code())
res += self.orig_code_visualized
return res
Expand Down

0 comments on commit 71ad977

Please sign in to comment.