add sorting by XO-cost priority pagename
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 8 Apr 2023 16:02:08 +0000 (17:02 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 8 Apr 2023 16:02:10 +0000 (17:02 +0100)
openpower/sv/rfc/ls012.mdwn
openpower/sv/rfc/ls012_optable.py

index a7b75ddff4fcb04b7d8c82021f9822d25144fe3e..f725ddf2c62cc7a0449dc5604425aa34bbce6651 100644 (file)
@@ -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]]
index 7c2d331fcbd10acf503cb920585aca816f221d97..846819ed0f799bec4cb21e551e7819ab9f238c21 100644 (file)
@@ -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)
+