Bug 396 - create simulator PowerISA div/mod functions
Summary: create simulator PowerISA div/mod functions
Status: IN_PROGRESS
Alias: None
Product: Libre-SOC's first SoC
Classification: Unclassified
Component: Source Code (show other bugs)
Version: unspecified
Hardware: All All
: --- enhancement
Assignee: Jacob Lifshay
URL:
Depends on:
Blocks: 383 324
  Show dependency treegraph
 
Reported: 2020-06-20 12:42 BST by Luke Kenneth Casson Leighton
Modified: 2020-07-14 16:15 BST (History)
2 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 Luke Kenneth Casson Leighton 2020-06-20 12:42:16 BST
using these for guidance, create functions for ISACaller div / mod that
provide overflow and result capability compatible with PowerISA

https://salsa.debian.org/Kazan-team/power-instruction-analyzer/-/blob/master/src/instr_models.rs
Comment 1 Jacob Lifshay 2020-06-21 21:05:36 BST
Assuming this bug is for translating/binding functions to python to allow use as a reference for test cases and in other python code, correct me if I'm wrong.
Comment 2 Luke Kenneth Casson Leighton 2020-06-21 21:51:45 BST
(In reply to Jacob Lifshay from comment #1)
> Assuming this bug is for translating/binding functions to python to allow
> use as a reference for test cases and in other python code, correct me if
> I'm wrong.

yes, correct.  the only discrepancy: the test cases are actually a test
of an actual full cycle-accurate python-based simulator intended to be
compliant with POWER9.

that simulator is not intended to be "just a unit test".  it's being
developed as a full stand-alone simulator in its own right.

in that context it becomes clear that the simulator (top-level class
"ISACaller") needs to have a full compatible implementation *in its own right*
of the PowerISA DIV and MOD instructions.

it just so happens that this makes comparison against the RTL - by running
"parallel implementations" (one ISACaller, one nmigen) against each other
and cross-checking the results.
Comment 3 Luke Kenneth Casson Leighton 2020-06-25 17:58:36 BST
jacob can i ask you if you could check something:

can you write a function that multiplies the result by the divisor
and checks that the result is equal to the dividend in all cases
where overflow is *not* true, and conversely when it is not equal
that the overflow *is* true?

i have a sneaking suspicion that this will be the case, and consequently
the function in the simulator which checks for "overflow" may be a
simple one-liner: "overflow = (divisor * result) != dividend"

as we are not concerned (at all) about speed in the simulator, this will
do the trick.
Comment 4 Jacob Lifshay 2020-06-25 18:02:45 BST
(In reply to Luke Kenneth Casson Leighton from comment #3)
> jacob can i ask you if you could check something:
> 
> can you write a function that multiplies the result by the divisor
> and checks that the result is equal to the dividend in all cases
> where overflow is *not* true, and conversely when it is not equal
> that the overflow *is* true?

That's incorrect, as the simple example of 3/2 will show:

3/2 -> 1
1*2 == 2 != 3
Comment 5 Luke Kenneth Casson Leighton 2020-06-25 18:13:16 BST
(In reply to Jacob Lifshay from comment #4)
> (In reply to Luke Kenneth Casson Leighton from comment #3)
> > jacob can i ask you if you could check something:
> > 
> > can you write a function that multiplies the result by the divisor
> > and checks that the result is equal to the dividend in all cases
> > where overflow is *not* true, and conversely when it is not equal
> > that the overflow *is* true?
> 
> That's incorrect, as the simple example of 3/2 will show:
> 
> 3/2 -> 1
> 1*2 == 2 != 3

drat.  oh wait!  plus the modulo.  if you add the modulo that brings it
to par.

but... hmmm that means computing the modulo in tandem.

i'm looking for ways to avoid having to reproduce the entire computation
just to calculate the overflow.

the alternative - which i am not happy about - is to modify the pseudocode
to return an overflow flag and detect the condition *in* the pseudocode
itself.
Comment 6 Luke Kenneth Casson Leighton 2020-06-30 11:32:08 BST
"solved" this by modifying the div/mod pseudocode so that it works out the overflow
condition.
Comment 7 Jacob Lifshay 2020-06-30 11:45:02 BST
(In reply to Luke Kenneth Casson Leighton from comment #6)
> "solved" this by modifying the div/mod pseudocode so that it works out the
> overflow
> condition.

I'd suggest submitting the changed pseudo-code to OpenPower since they may incorporate it in the next revision of the Power ISA spec.
Comment 8 Luke Kenneth Casson Leighton 2020-06-30 12:03:28 BST
(In reply to Jacob Lifshay from comment #7)
> (In reply to Luke Kenneth Casson Leighton from comment #6)
> > "solved" this by modifying the div/mod pseudocode so that it works out the
> > overflow
> > condition.
> 
> I'd suggest submitting the changed pseudo-code to OpenPower since they may
> incorporate it in the next revision of the Power ISA spec.

really need to check it first, with the unit tests.