From 29c507b784b60a5e1c76fdc79c657121574bf551 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sat, 8 Apr 2023 17:02:08 +0100 Subject: [PATCH] add sorting by XO-cost priority pagename --- openpower/sv/rfc/ls012.mdwn | 1 + openpower/sv/rfc/ls012_optable.py | 81 ++++++++++++++++++++++++++++--- 2 files changed, 75 insertions(+), 7 deletions(-) diff --git a/openpower/sv/rfc/ls012.mdwn b/openpower/sv/rfc/ls012.mdwn index a7b75ddff..f725ddf2c 100644 --- a/openpower/sv/rfc/ls012.mdwn +++ b/openpower/sv/rfc/ls012.mdwn @@ -332,5 +332,6 @@ thus they are best placed in EXT0xx. [[!inline pages="openpower/sv/rfc/ls012/areas.mdwn" raw=yes ]] +[[!inline pages="openpower/sv/rfc/ls012/xo_cost.mdwn" raw=yes ]] [[!tag opf_rfc]] diff --git a/openpower/sv/rfc/ls012_optable.py b/openpower/sv/rfc/ls012_optable.py index 7c2d331fc..846819ed0 100644 --- a/openpower/sv/rfc/ls012_optable.py +++ b/openpower/sv/rfc/ls012_optable.py @@ -2,6 +2,7 @@ # generates markdown tables from CSV files, after doing lovely sorting # by different columns, blah blah... from copy import deepcopy +import functools def write_mdwn_row(f, row): row = "|".join(row) @@ -14,6 +15,69 @@ def underlines(header): row.append("-" * len(col)) return row +# sorting functions +def is_svp64_page(page): + return page in ['sv/setvl', 'sv/svstep', 'sv/remap'] + +def sort_by_page(p1, p2): + p1 = p1['page'] + p2 = p2['page'] + if not (is_svp64_page(p1) ^ is_svp64_page(p2)): + if p1 < p2: return -1 + if p1 > p2: return 1 + return 0 + if is_svp64_page(p1): + return -1 + if is_svp64_page(p2): + return 1 + return 0 + +priorities = ['high', 'med', 'low', 'TBD'] + +def sort_by_priority(p1, p2): + p1 = priorities.index(p1['priority']) + p2 = priorities.index(p2['priority']) + if p1 < p2: return -1 + if p1 > p2: return 1 + return 0 + +def sort_by_cost(p1, p2): + p1 = p1['cost'] + p2 = p2['cost'] + if not p1.isdigit(): p1 = 0 + if not p2.isdigit(): p2 = 0 + p1 = int(p1) + p2 = int(p2) + if p1 < p2: return -1 + if p1 > p2: return 1 + return 0 + +def sort_by_cost_priority_page(p1, p2): + v = sort_by_cost(p1, p2) + if v == 0: + v = sort_by_priority(p1, p2) + if v == 0: + v = sort_by_page(p1, p2) + return v + + +def by_cost_then_priority_then_page(areas): + # first blat all columns together (drop area-dict) + res = [] + for row in areas.values(): + res += row + # now sort them + res = sorted(res, key=functools.cmp_to_key(sort_by_cost_priority_page)) + # now split out into a dict again this time by cost-priority + costs = {} + for row in res: + cost = row['cost'] + if cost not in costs: + costs[cost] = [] + costs[cost].append(row) + return costs + + def print_table(title, header, areas, sortby): fname = title.lower().replace(" ", "_") with open("ls012/%s.mdwn" % fname, "w") as f: @@ -29,6 +93,11 @@ def print_table(title, header, areas, sortby): # start writing out areas for title, rows in areas.items(): # start new page (if not first newpage) + if linecount is not None: + # allow 60 rows per page + linecount += len(rows) + if linecount >= 60: + linecount = 0 if linecount == 0: f.write("\\newpage{}\n") f.write("\n") @@ -64,13 +133,8 @@ def print_table(title, header, areas, sortby): write_mdwn_row(f, r) f.write("\n\n") - # approx 6 lines per header - linecount += 6 - - # allow 60 rows per page - linecount += len(rows) - if linecount >= 60: - linecount = 0 + # approx 8 lines per header + linecount += 9 if __name__ == '__main__': with open("ls012/optable.csv") as f: @@ -100,3 +164,6 @@ if __name__ == '__main__': # area - list-of-instructions - dictionary-by-heading print_table("Areas", header, areas, None) + # now sort by cost and then by page + print_table("XO cost", header, areas, by_cost_then_priority_then_page) + -- 2.30.2