Bug 901 - Formal proof for PriorityPicker and MultiPriorityPicker and BetterMultiPriorityPicker
Summary: Formal proof for PriorityPicker and MultiPriorityPicker and BetterMultiPriori...
Status: RESOLVED FIXED
Alias: None
Product: Libre-SOC's first SoC
Classification: Unclassified
Component: Formal Verification (show other bugs)
Version: unspecified
Hardware: PC Linux
: --- enhancement
Assignee: Jacob Lifshay
URL:
Depends on:
Blocks: 198
  Show dependency treegraph
 
Reported: 2022-08-03 05:19 BST by Jacob Lifshay
Modified: 2022-08-28 17:52 BST (History)
3 users (show)

See Also:
NLnet milestone: ---
total budget (EUR) for completion of task and all subtasks: 0
budget (EUR) for this task, excluding subtasks' budget: 0
parent task for budget allocation:
child tasks for budget allocation:
The table of payments (in EUR) for this task; TOML format:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jacob Lifshay 2022-08-03 05:19:24 BST
DONE: PriorityPicker
DONE: MultiPriorityPicker
DONE: BetterMultiPriorityPicker
Comment 1 Jacob Lifshay 2022-08-03 06:42:17 BST
I completed the formal proof for PriorityPicker, which turned out to be quite broken:
the lsb_mode parameter when set to False (the default) actually changed it to LSB-priority. When set to True, it was just plain broken.
Since nothing actually uses lsb_mode=True or even sets it (except for dumping PriorityPicker as rtlil for user inspection), I renamed it to msb_mode and fixed its operation when set to True.

https://git.libre-soc.org/?p=nmutil.git;a=blobdiff;f=src/nmutil/picker.py;h=7cf7f7bd03001f920ce898ab765211d7689832ad;hp=8df01e783445f53e623e61eac7e1ef3698ed660b;hb=406a59ee96b948810f274151808c1551517d28f2;hpb=8aa377705c96f365606950c0fa142e40546e566b
Comment 2 Jacob Lifshay 2022-08-04 06:53:20 BST
I added the formal proof for MultiPriorityPicker.

While I was reading the implementation, I thought of a more efficient implementation with O(log N) latency instead of the > O(N) latency that MultiPriorityPicker has, so I wrote BetterMultiPriorityPicker:

it uses a parallel prefix sum of the input bits to compute which level each input bit should be sent to, rather than needing a O(N) stack of PriorityPickers.

Testing with width=16, levels=16:

The new algorithm uses a bit less gates and has about 1/4 the latency:

> yosys <<<$'read_rtlil sim_test_out/nmutil.formal.test_picker.TestBetterMultiPriorityPicker.test_16_levels_16_idxs_f_mi_f/0.il\nflatten\nsynth\nltp -noff'

Number of cells:               1171
Longest topological path in top (length=21):

> yosys <<<$'read_rtlil sim_test_out/nmutil.formal.test_picker.TestMultiPriorityPicker.test_16_levels_16_idxs_f_mi_f/0.il\nflatten\nsynth\nltp -noff'

Number of cells:               1469
Longest topological path in top (length=85):
Comment 3 Luke Kenneth Casson Leighton 2022-08-04 10:06:21 BST
yes brilliant, i did a proof-of-concept version
based on PPicker as it is easier to think through
but nowhere neae gate-efficient.  nicely done.