Use of DIV and MOD for bit manipulation
Dear All, While reading compiler code(OBG.Mod.txt), I see that in many places we have used DIV, MOD, multiplication etc. No doubt, one can argue that, we want to do a mathematical operation there, but to be honest, the interest there is not to do a mathematical operation; rather to do some bit manipulation. And, since we know that DIV and MOD can help us there, we employ them. How shall we justify it (to obscure the natural meaning)? Isn't the code clarity being compromised there? I would like to know, how Oberoners think about it... With thanks and best regards, Yours sincerely, Srinivas Nayak Home: http://www.mathmeth.com/sn/ Blog: http://srinivas-nayak.blogspot.in/
That's a very deep topic. We also don't really want to do 'bit manipulation', ..nor even the control of the underlying semiconductors, ...nor even their current flow, .. nor even ... It's less determined by technology than socio-economic factors. It's the cost of mental effort, for getting from what-we-have-already-paid-for by way of education, to our target. DIV & MOD are more familiar for 'programmers'. But yes, going lower would be <mentally cheaper> for engineers. == Chris Glur.
Srinivas Good question. The intention of Oberon was to be on one side a high-level language but nevertheless be able to write low-level code wherever interaction with HW is needed (device drivers, compilers...) In the past, Wirth found that it is not necessary to foresee special language constructs for this kind of low level programming. If bitwise AND and OR are needed, use the type SET instead of INTEGER. He thought that almost all needed bit manipulations can be done by applying standard language constructs like DIV, MOD and *. In his former languages Modula-2 and Oberon the only special language construct for bit manipulation was the standard procedure ASH. Over the time it seems he changed his way of thinking. In Oberon-07 these special language constructs were introduced: LSL, ASR and ROR. And if urgently needed, you can even make use of SYSTEM.BIT, SYSTEM.LSH and SYSTEM.ROT. So, basically using DIV, MOD and * (with powers of two) is for Oberoners the "normal" way to shift bits. In ORG.Mod you will find in procedures MulOp, DivOp the special handlings for power of two. DivOp div --> ASR mod --> AND MulOp --> LSL Jörg -----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Srinivas Nayak Sent: Samstag, 9. Juli 2016 15:20 To: ETH Oberon and related systems <oberon@lists.inf.ethz.ch> Subject: [Oberon] Use of DIV and MOD for bit manipulation Dear All, While reading compiler code(OBG.Mod.txt), I see that in many places we have used DIV, MOD, multiplication etc. No doubt, one can argue that, we want to do a mathematical operation there, but to be honest, the interest there is not to do a mathematical operation; rather to do some bit manipulation. And, since we know that DIV and MOD can help us there, we employ them. How shall we justify it (to obscure the natural meaning)? Isn't the code clarity being compromised there? I would like to know, how Oberoners think about it... With thanks and best regards, Yours sincerely, Srinivas Nayak Home: http://www.mathmeth.com/sn/ Blog: http://srinivas-nayak.blogspot.in/ -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Thank you Jorg. Yes, I can also see use of ASR and ROR in ReadNum and WriteNUm. With thanks and best regards, Yours sincerely, Srinivas Nayak Home: http://www.mathmeth.com/sn/ Blog: http://srinivas-nayak.blogspot.in/ On 07/11/2016 06:21 PM, Jörg wrote:
Srinivas
Good question. The intention of Oberon was to be on one side a high-level language but nevertheless be able to write low-level code wherever interaction with HW is needed (device drivers, compilers...)
In the past, Wirth found that it is not necessary to foresee special language constructs for this kind of low level programming. If bitwise AND and OR are needed, use the type SET instead of INTEGER. He thought that almost all needed bit manipulations can be done by applying standard language constructs like DIV, MOD and *. In his former languages Modula-2 and Oberon the only special language construct for bit manipulation was the standard procedure ASH.
Over the time it seems he changed his way of thinking. In Oberon-07 these special language constructs were introduced: LSL, ASR and ROR. And if urgently needed, you can even make use of SYSTEM.BIT, SYSTEM.LSH and SYSTEM.ROT.
So, basically using DIV, MOD and * (with powers of two) is for Oberoners the "normal" way to shift bits.
In ORG.Mod you will find in procedures MulOp, DivOp the special handlings for power of two. DivOp div --> ASR mod --> AND MulOp --> LSL
Jörg
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Srinivas Nayak Sent: Samstag, 9. Juli 2016 15:20 To: ETH Oberon and related systems <oberon@lists.inf.ethz.ch> Subject: [Oberon] Use of DIV and MOD for bit manipulation
Dear All,
While reading compiler code(OBG.Mod.txt), I see that in many places we have used DIV, MOD, multiplication etc. No doubt, one can argue that, we want to do a mathematical operation there, but to be honest, the interest there is not to do a mathematical operation; rather to do some bit manipulation. And, since we know that DIV and MOD can help us there, we employ them.
How shall we justify it (to obscure the natural meaning)? Isn't the code clarity being compromised there?
I would like to know, how Oberoners think about it...
With thanks and best regards,
Yours sincerely, Srinivas Nayak
Home: http://www.mathmeth.com/sn/ Blog: http://srinivas-nayak.blogspot.in/ -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
participants (3)
-
eas lab -
Jörg -
Srinivas Nayak