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

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.

(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.

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.

(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

(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.

"solved" this by modifying the div/mod pseudocode so that it works out the overflow condition.

(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.

(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.