Re: [Oberon] Assumed issue in the Lola-2 compiler
@ Paul Reed:
The result of x [= -1] DIV 10H is -1, because it is implemented as an arithmetic shift right, in turn because the divisor is a constant power of two.
Thank you for the clarification. Is there a formal specification somewhere of how the DIV operator exactly works? I read quite a lot of stuff about Oberon but didn't find an indication so far that "-1 DIV 16 = -1". Can you give me a hint please where I can find a complete specification, a value table or at least a reference implementation? Best R.K.
Thank you for the clarification. Is there a formal specification somewhere of how the DIV operator exactly works?
Not really... what's not specifically defined in the Oberon language report is normally intentionally left undefined; then implementors look at the behaviour of Prof. Wirth's compilers to find direction on how to implement something in order to be compatible, but the choice is basically up to them. So I would suggest looking at how the Oberon RISC compiler generates code, as the easiest route. Cheers Paul
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of rochus.keller@bluewin.ch Sent: Monday, 15 April 2019 8:02 PM To: oberon@lists.inf.ethz.ch Subject: Re: [Oberon] Assumed issue in the Lola-2 compiler
@ Paul Reed:
The result of x [= -1] DIV 10H is -1, because it is implemented as an arithmetic shift right, in turn because the divisor is a constant power of two.
Thank you for the clarification. Is there a formal specification somewhere of how the DIV operator exactly works? I read quite a lot of stuff about Oberon but didn't find an indication so far that "-1 DIV 16 = -1". Can you give me a hint please where I can find a complete specification, a value table or at least a reference implementation?
In the Oberon-07 Language Report DIV and MOD are defined as follows: ------------------------------------------------------------------ The operators DIV and MOD apply to integer operands only. Let q = x DIV y, and r = x MOD y. Then quotient q and remainder r are defined by the equation a) x = q*y + r b) 0 <= r < y ------------------------------------------------------------------ Hence, in the case of -1 DIV 16, x = -1 and y = 16. Therefore, substituting for x and y in a): -1 = q * 16 + r Rearranging: q = -(r + 1) / 16 therefore to satisfy the constraint b) on r, for integer r and q, r must equal 15 and therefore q = -16 / 16 = -1. There was a lengthy discussion somewhat related to this in this mailing list a couple of years ago: http://lists.inf.ethz.ch/pipermail/oberon/2017/010355.html Regards, Chris Burrows CFB Software http://www.astrobe.com
participants (3)
-
Chris Burrows -
Paul Reed -
rochus.keller@bluewin.ch